Documente Academic
Documente Profesional
Documente Cultură
OF
DATA & FILE STRUCTURES
[ TOPIC: ONE-WAY LINK LIST ]
SUBMITTED TO :
DR. VISHAL GOYAL
SUBMITTED BY:
140454170
140454194
140454218
140454222
140454272
( M.C.A. 1ST - B)
Contents
Introduction To Linked list
The first part is known as info part which holds the element.
Info
401
402
401
402
414
Null
414
10
Begin
104
102
103
Null
Pointer
102
11
Memory Allocation/Deallocation
13
14
At end
15
Insertion At Beginning
Begi
n
Begin
12
401
Null
88
414 Null
400
New
16
17
Insertion At End
If list is empty, store null value in next part of new node and insert
item in the info part
If list is not empty, traverse list till end node.
Store address of new node into next part of the last node of the
linked list and the next part set to null.
Pointer
Begi
n
40
1
40
2
41
4
Null
New
405
Null
18
20
Begin
401
402
414
Null
Pointe
r
New
Item
New Next=Pointer
Next
Pointer
Next=New
21
Algorithm :
Else
Allocate space to node New
Set New=Free, Free=Free Next, New Info=Item
Set New Next=Pointer Next
Set Pointer Next=New
[End If]
Step 5: Exit
23
24
Begin
401
405
408
Null
Pointer
New
403
25
Algorithm
Step 4: Repeat While Pointer2 Null and Item > pointer2 Info
Set Pointer1 = Pointer2 and Pointer2 = Pointer2 Next
[End loop]
Step 5: If Free = Null Then
Print : No space for insertion , Allocation of space to node
New is not possible
Exit
[End If]
Step 6: Allocate space to node New
Set New = Free and Free = Free Next
Step 7: Set New Info = Item
Step 8: If Pointer2 = Null Then
Set Pointer1 Next = New and New Next = Null
Else
Set New Next = Pointer Next
Set Pointer1 Next = New
[End If]
27
Step 9: Exit
28
Begin
Free
401
402
414
Null
Null
29
30
31
Begin
401
Pointer1
402
414
Null
Pointer2
Free
Pointer1 = Begin
Pointer2 = BeginNext
NULL
Null
Pointer1 = Pointer2
Pointer2 = Pointer2 Next
Pointer1 Next=Pointer2
Next
Pointer2 Next=Free
Free=Pointer2
32
34
35
17
Null
Pointer2
Free
Null
38
39
Begin
1
25
17
38
Null
Pointe
r
Begin
2
25
17
38
Null
Algorithm:
Begin2
25
10
27
17
42
30
Null
Null
43
After Merging
Begin
1
25
27
42
Null
10
17
30
Null
Pointer1
Begin2
Pointer2
Begin
10
17
25
27
30
42
Null
44
Else
Set New Info=Begin1 Info and New Next=Null
Set Pointer1=Begin1 Next and Pointer2=Begin2
[End If]
Step 5: Set Begin=New and Pointer =New
Step 6: Repeat steps 7and 8 while Pointer1Null and Pointer2 Null
Step 7: If Free=Null then
Print No free space available
Exit
Else
Set New =Free and Free=Free Next
[End If]
Step 8: If Pointer1 Info Pointer2 Info then
Set New Info=Pointer2 Info
Set New Next=Null
Set Pointer Next=New
Set Pointer=New and Pointer2=Pointer2 Next 46
[End If]
[End Loop]
Step 9: If Pointer1=Null and Free Null then
Repeat while Pointer2 Null
a. Set New=Free and Free=Free Next
b. Set New Info=Pointer2 Info and
New Next =Null
c. Set Pointer Next=New
d. Set Pointer =New and Pointer2=Pointer2 Next
[End Loop]
Else
Repeat while Pointer1 Null
a. Set New=Free and Free=Free Next
b. Set New Info=Pointer1 Info and
New Next=Null
c.Set Pointer Next=New
d. Set Pointer=New and Pointer1=Pointer1 47 Next
[End Loop]
[End If]
Step 10: If Pointer1 = Null And Pointer2=Null Then
Print: The given link lists merged successfully
Else
Print Not Enough space
[End If]
Step 11: Exit
48
Begin
10
17
25
27
28
32
Pointer
Begin
1
10
17
25
Null
27
28
32
Null
Begin
2
50
Null
Algorithm:
Step 9:
52
53
Begin
1
5
10
Null
Begin
2
Null
10
54
Begin
10
17
25
27
28
42
Null
Begin
10
Null
17
25
27
28
42
55
Algorithm:
Link List
Step 1: If Begin = Null Then
Print: No node is present in link list
Exit
[End If]
Step 2: If Begin Next = Null Then
Print: link list is having only one node
Exit
[End If]
Step 3: If Begin Next Null Then
Set Pointer1 = Begin
Set Pointer2 = Begin Next
Set Pointer3 = Pointer2 Next
[End If]
56
57
END
THANKS
58