Create f8

This commit is contained in:
havya1310 2018-10-27 11:27:08 +05:30 committed by GitHub
parent 3468d27e61
commit efc25333b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

37
f8 Normal file
View file

@ -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;
}