Q. Write down an algorithm to add an element in the end of the circular linked list.
Ans.
Algorithm to Add the Element at the End of Circular Linked Lists written below.
IINSENDCLL( INFO, LINK, START, AVAIL, ITEM) The algorithm deletes last element from the circular linked list.
1. [OVERFLOW?] if AVAIL = NULL, then Write:
OVERFLOW, and Exit.
2. [Remove first node from the AVAIL: = LIN[AVAIL].
a. Set NEW:= AVAIL and AVAIL:=LINK[AVAIL].
3. Set INFO[NEW]:=ITEM. [copies new data into new node.]
4. Set PTR:= LINK[START] and SAVE:=START.[initializes popinters]
5. Repeat while LINK[PTR]!=START: [ Traverses list seeking last node.]
a. Set PTR:=LINK[PTR]. [Updates PTR] [ End of loop]
6. Set LINK [PTR]:= NEW. [ Attaches new node to the last node of the list]
7. Set LINK[NEW]:= START [ New node now points to the original first node.]
8. Exit