Professional Documents
Culture Documents
Linked List
Linked List
Pointer basics
• A pointer is a variable that holds the memory address of another object.
• General form of pointer declaration:
type *var_name;
Here, type is the base type of the pointer.
The base type specifies the type of object that the pointer can point to.
(*p)++;
Increments the value pointed to by the pointer.
• These functions are defined under the C standard library header file called
<stdlib.h>.
struct node { 5 7 3 1
int value;
struct node *next;
}
1/27/2020 Prepared by Tasneea Hossain 22
Insertion into a Linked List
• A node can be added at first, last or after an interior node in the linked list.
Head
H E L L O
Head L null
• Next, the last node has to be detected and the current last node has to
point to the newly created node.
• To delete the first node of the linked list, the head pointer has to point to
the second node and the memory occupied by the abandoned node has to
be freed as well.
cur
head
cur head
2 7 4 9 1
Advantages:
Any node can be traversed to easily.
Saves time when we have to go from the last node to the first node
Disadvantages:
Since there are no NULLs to mark the end, the loop control is harder.