Professional Documents
Culture Documents
Procedure
CREATELIST(INFO,LINK,HEAD,VAL)
[ The procedure CREATELIST is used to
create the
Circular linked list.INFO is the array
containing the
information part and the LINK is the
array
containing the address of the next node or
NULL.
HEAD will contain the address of the first
node
or NULL if there is no node . VAL is
the
value for which the node is to be created.
]
Step 1: Set PTR:=HEAD.
Step 2: If PTR=NULL then :
[Linked list is empty,allocate
memory to TEMP]
(a) Set INFO(TEMP):=VAL.
(b) Set LINK(TEMP):=TEMP.
(c) Set HEAD:=TEMP.
Else :
[Linked list already contain some
node,traverse
till the last node is reached.]
2) VAL=5
PTR=HEAD=NULL.
PTR=NULL
3) val=10
(B) Procedure to print the Circular linked list
Procedure
PRINTLIST(INFO,LINK,HEAD)
[Procedure to print the Circular linked list.]
Procedure
INSERTLAST(PTR,LINK,HEAD,VAL)
[Procedure INSERTLAST is used to insert a
new node to the last node]
Step 1: Set PTR:=HEAD.
Step 2: Repeat Steps 3 to 3 while
LINK(PTR)!=HEAD do :
Step 3: Set PTR:=LINK(PTR).
[End of the while loop]
[Allocate memory to TEMP]
Step 4: Set INFO(TEMP):=VAL.
Step 5: Set LINK(TEMP):=HEAD.
Step 6: Set LINK(PTR):=TEMP.
Step 7: Return.
Procedure DELETELAST(PTR,LINK,HEAD)
[Procedure DELETELAST is used to to delete
the last node]
Step 1: Set PTR:=HEAD.
Step 2: Repeat Steps 3 to 4 while
LINK(PTR)!=HEAD do :
Step 3: Set PREVIOUS:=PTR.
Step 4: Set PTR:=LINK(PTR).
[End of the while loop]
[Allocate memory to TEMP]
Step 5: Set TEMP:=PTR.
Step 6: Set LINK(PREVIOUS):=HEAD.
Step 7: FREE(TEMP).
Step 8: Return.