From 10f64a736238c923214f727a1a1b416077194e82 Mon Sep 17 00:00:00 2001 From: Akshay Khatter <30326830+akshaykhatter@users.noreply.github.com> Date: Sat, 8 Oct 2022 01:50:59 +0530 Subject: [PATCH] added Insertion_of_node_at_tail_of_LinkedList --- ...nsertion_of_node_at_tail_of_LinkedList.cpp | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Linked_List/Insertion_of_node_at_tail_of_LinkedList.cpp diff --git a/Linked_List/Insertion_of_node_at_tail_of_LinkedList.cpp b/Linked_List/Insertion_of_node_at_tail_of_LinkedList.cpp new file mode 100644 index 00000000..f45b8544 --- /dev/null +++ b/Linked_List/Insertion_of_node_at_tail_of_LinkedList.cpp @@ -0,0 +1,65 @@ + +#include + +using namespace std; + + + +struct Node +{ + int data; + struct Node *next; +}; + +struct Node *head; + +void +Insert (int data) +{ + struct Node *temp = (struct Node *) malloc (sizeof (struct Node *)); + + + temp->data = data; + temp->next = NULL; + + if (head == NULL) + { + head = temp; + return; + } + + struct Node *temp2 = head; + while (temp2->next != NULL) + { + temp2 = temp2->next; + } + temp2->next = temp; +} + +void +Print () +{ + struct Node *temp = head; + while (temp != NULL) + { + printf (" %d", temp->data); + temp = temp->next; + } + printf ("\n"); + +} + + +int +main () +{ + head = NULL; + Insert (4); + Insert (6); + Insert (8); + Insert (2); + Print (); + + return 0; +} +