From efc25333b523a6ea1c865b9f9528d084ad64a6bd Mon Sep 17 00:00:00 2001 From: havya1310 <44518163+havya1310@users.noreply.github.com> Date: Sat, 27 Oct 2018 11:27:08 +0530 Subject: [PATCH] Create f8 --- f8 | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 f8 diff --git a/f8 b/f8 new file mode 100644 index 00000000..221014ab --- /dev/null +++ b/f8 @@ -0,0 +1,37 @@ +struct Node *addAfter(struct Node *last, int data, int item) +{ + if (last == NULL) + return NULL; + + struct Node *temp, *p; + p = last -> next; + + // Searching the item. + do + { + if (p ->data == item) + { + // Creating a node dynamically. + temp = (struct Node *)malloc(sizeof(struct Node)); + + // Assigning the data. + temp -> data = data; + + // Adjusting the links. + temp -> next = p -> next; + + // Adding newly allocated node after p. + p -> next = temp; + + // Checking for the last node. + if (p == last) + last = temp; + + return last; + } + p = p -> next; + } while (p != last -> next); + + cout << item << " not present in the list." << endl; + return last; +}