mirror of
https://github.com/trailofbits/algo.git
synced 2025-08-14 00:33:02 +02:00
Create f8
This commit is contained in:
parent
3468d27e61
commit
efc25333b5
1 changed files with 37 additions and 0 deletions
37
f8
Normal file
37
f8
Normal 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;
|
||||
}
|
Loading…
Add table
Reference in a new issue