MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / insert

Function insert

CPP/LINKED LIST/Linked_list.cpp:68–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68void insert(struct Node *p, int index, int data)
69{
70 // new node in heap
71 struct Node *newNode;
72 newNode = new struct Node;
73 newNode->data = data;
74
75 if (index == 0)
76 {
77 // linking
78 newNode->next = first;
79 first = newNode;
80 }
81
82 else
83 {
84 for (int i = 0; i < index - 1; i++)
85 {
86 p = p->next;
87 }
88
89 newNode->next = p->next;
90 p->next = newNode;
91 }
92
93}
94
95void deleteList(struct Node *p , int index)
96{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected