PPT2 - Linked List I - Single Linked List
PPT2 - Linked List I - Single Linked List
PPT2 - Linked List I - Single Linked List
• Linked list which node contain only a single link to other node is called
single linked list.
• Linked List:
Linear collection of nodes
Doesn’t store its nodes in consecutive memory locations
Can be accessed only in a sequential manner
6
Single Linked List
• To create a list, we first need to define a node
structure for the list.
9
Single Linked List:
Push (Insert)
How about the algorithm of inserting new node in the
middle and in the last of the single linked list?
// if x is in head node
if ( head->value == x ) {
head = head->next;
free(curr);
}
// if x is not in head node, find the location
else {
while ( curr->next->value != x ) curr = curr->next;
struct tnode *del = curr->next;
curr->next = del->next;
free(del);
}
6 3 9 2 7 1 1 0 x