Linked List2
Linked List2
2 2
Creating a List
• LIST – Linked list
START = 1000
List – linked list in a memory. This procedure finds the total number of
elements in the LIST.
List – linked list in a memory. This procedure search location (LOC) of particular ITEM
in a list.
Set LOC = NULL
SEARCH (INFO, LINK, START, ITEM,LOC)
1. Set PTR := START [Initialize Pointer]
2. Repeat Steps 3 while PTR ≠ NULL:
3. If ITEM < INFO[PTR], then:
Set PTR:=LINK[PTR]. [PTR now points to next_node]
Else If ITEM =INFO[PTR], then:
Set LOC:=PTR and Exit
Else:
Set LOC:=NULL, and Exit
[End of IF Structure]
[End of Step 2 loop.]
4. Set LOC:=NULL.
5. Exit.
Memory Allocation, Garbage Collection
• For insertion- provide unused memory space to the new
nodes.
INFO LINK
1
START 2
3 O 6
4
9
5
6 R 11
7 K Null
8 10
9 N 3
AVAIL
10 4
12 11 E 7
12 8
Garbage Collection
• Suppose some memory space becomes reusable because a node is
deleted from a list or an entire list is deleted from a program.
• We want the space available for future use. - One way to bring this
about is to immediately reinsert the space into the free storage list.
• And then computer runs through the memory, collecting all untagged space
onto the free storage list.
Overflow and Underflow
• Sometimes new data are to be inserted into a data structure but there
is no available space, the free storage list is empty.
• When one want to delete data from a data structure that is empty –
underflow.
For queries
Email: [email protected]
20