Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Link list
1. 1-1
Link List
Definition:
A link list is a linear collection of data element,
called nodes. The linear order is given by pointers.
Each node is divided into two or more parts.
Types of link list:
1.Singly link list.
2.Circular link list.
3.Doubly link list.
4.Doubly circular link list.
2. 4-2
Link List
Advantages:
1. Link list are dynamic data structure.
2. Efficient memory utilization.
3. Insertion and deletion are easier.
Disadvantages:
1. If the number of fields are more then more memory
space is needed.
2. Access to an data item is little bit time consuming.
3. 4-3
Singly-link list
Singly link list:
A singly link list is one in which all nodes are
linked together in some sequential manner. Hence, it is
also called linear linked list. It contains mainly two
parts.
1.Data part .
2.Address part(next).
Example : We have three node as shown in figure:
Data DataDataNext Next Next
Node 1 Node 2 Node 3
NULL
Head Tail
4. 4-4
Singly-link list
Insertion in the Singly link list
1.Insertion at beginning:-
Logic:
1.temp->next=head.
2.head=temp.
10 200 3020 300 NULL
100 200 300
Head Tail
5
Temp
50
New node
100
5. 4-5
Singly-link list
Insertion in the Singly link list
1.Insertion at Middle:-
Important terms:
1.Cur=head.
2.Specify position…lets 3rd
.
3.Take variable i=1.
10 200 3020 300 NULL
200 300
Head Tail
5
Temp
50
New node
100
while(pos!=i+1)
{
cur=cur->next;
i++;
}
6. 4-6
Singly-link list
Insertion in the Singly link list
1.Insertion at Middle:-
Looping:
10 200 3020 300 NULL
200 300
Head Tail
5
Temp
50
New node
100
1st
.pos==3&&i== 2.
condition true
cur=cur->next &&
increase I with 1.
2nd
.pos==3&&i==3
condition false
exit from loop.
Cur
7. 4-7
Singly-link list
Insertion in the Singly link list
1.Insertion at Middle:-
Logic:
1.temp->next=cur->next.
2.cur->next=temp.
10 200 3020 300 NULL
200 300
Head Tail
5
Temp
50
100
Cur
300
50
8. 4-8
Singly-link list
Insertion in the Singly link list
1.Insertion at End:-
Logic:
1.tail->next=temp.
2.tail=temp.
3.tail->next=NULL.
10 200 3020 300 NULL
200 300
Head Tail
5
Temp
50
New node
100 50
NULL
9. 4-9
Singly-link list
Deletion in the Singly link list
1.Deletion at Begin:-
Logic:
1.temp=head.
2.head=head->next.
3.free(temp).
10 200 3020 300 50
200 300
Head Tail
5
50100 50
NULL
Want to delete
Temp HeadHead
10. 4-10
Singly-link list
Deletion in the Singly link list
1.Deletion at Middle:-
Important Terms:
1.Specify variables pos & i=1
2.Take cur=head & Temp.
3.Start looping.
10 200 3020 300 50
200 300
Head Tail
5
50100 50
NULL
Want to delete
Head
while(pos!=i+1)
{
cur=cur->next;
i++;
}
Cur
11. 4-11
Singly-link list
Deletion in the Singly link list
1.Deletion at Middle:-
Logic:
1.if(pos==i++).
2.temp=cur->next.
3.cur->next=temp->next.
4.free(temp).
10 200 3020 300
200 300
Head Tail
5
50100 50
NULL
Want to delete
Head Cur Temp
50
50
12. 4-12
Circular-link list
Circular link list:
A circular link list is just like a singly link list
but the difference is that the last node of the circular
link list will contains that address of first node. It will
also contains tow parts.
1.Data part .
2.Address part(next).
Example : We have three node as shown in figure:
Data DataDataNext Next Next
Node 1 Node 2 Node 3
Head Tail
13. 4-13
Doubly Circular
Doubly circular link list:
A doubly circular link list is that whose last node contains
the address of first node and the first node contains the
address of last node. It contains three parts.
1.Data
2.Address of previous node(prev).
3.Address of next node(next).
Example: We have three node as shown in figure:
Node 1
prev Data Next prev Data Next
Node 2
prev Data Next
Node 3
Head Tail
14. Link list(Doubly Circular)
• Insertion at beginning & at end in D circular
1.Insertion at beginning:
Logic:
1. Temp->next=head.
2. Temp->prev=head->prev.
3. head=Temp.
4. Tail->next=head;
4-14
300 10
100 200 300
200 100 20 300 200 30 1005
New node
Head Tail
50
Temp
100300 50 50
15. Link list(Doubly Circular)
2.Insertion at End:
Logic:
1. temp->next=tail->next
2. tail->next=temp.
3. temp->prev=tail.
7. tail=temp.
8. head->prev=tail.
4-15
10
100
200
300200
10020300 200 30300100
Head Tail
40
Temp
New node
100
400
400 300
Tail
400