C++ program using linked list operations

June 20, 2016

Aim:

To write a program to implement linear linked list operations.

Algorithm:

Insert ( );

INFIRST (INFO, LINK, START, AVAIL, ITEM)

This algorithm inserts ITEM as the first node in the list.

1.     [OVERFLOW?] If AVAIL = NULL, then : Write : OVERFLOW, and Exit.

2.    [Remove first node from AVAIL list. ]

       Set NEW : = AVAIL and AVAIL : = LINK [AVAIL].

3.   Set INFO[NEW] : = ITEM. [Copies new data into new node. ]

4.   Set LINK[NEW] : = START. [New node now points to original first node. ]

5.   Set START : = NEW. [Changes START so it points to the new node. ]

6.   Exit.

Delete ( );

DEL ( INFO, LINK, START, AVAIL, LOC, LOCP)

This algorithm deletes the node N with location LOC, LOCP is the location of the node which precedes N or, when N is the first node, LOCP = NULL.

1.    If LOCP = NULL, then:

         Set START : = LINK [START]. [Deletes first node.]

         Else:

        Set LINK [LOCP] : = LINK[LOC]. [Deletes node N.]

        [End of If structure.]

2.    [Return deleted node to the AVAIL list.]

        Set LINK[LOC] : = AVAIL and AVAIL : = LOC.

3.   Exit.

Program code:

Output:

Tagged in: ,
About Author
Adeeb C (219 Articles)

Adeeb C is the founder of this website. He is a blogger and web developer. And he writes about latest technology news, gadgets and windows since last four years.