Mar 14, 2011

Circular Singly Linked List


A singly circular linked list is a linked list in which the last node of the list point to the first node in the list.
          In Circular linked list, we can start at any node in the list & travel the whole list. For this reason we can make our external pointer to the list pointer to any node & still access all the node in the list.

Mar 12, 2011

Algorithm for the print the doubly list


Procedure PRINT (TEMPHEAD)
[This procedure print the element of the node in the LIFO and FIFO format and TEMPHEAD points the first element of the list]

1. [Check for the empty list]
          If TEMPHEAD = NULL
                   Then write (“Empty list”)
                   Return
2. [First in first out]
          Repeat while RPTR (TEMPHEAD)! = NULL
                   Write (INOF (TEMPHEAD))
3. [Last in first out]
          Repeat while TEMPHEAD! = NULL
                   Write (INFO (TEMPHEAD))
4. [Finished]                  
            Return                        

Algorithm for the deleting an element from the doubly linked list


Function DELETE (TEMPHEAD, KEY)
[This Function delete an element from the doubly list and returns the address of the first element TEMPHEAD is pointer which points the first element of the list and KEY specify info of the node which is to be deleted]

1. [Check for the empty list]
          If TEMPHEAD = NULL
                   Then write (“Empty list”)
                   Return
2. [Deletion of the first node]
          TEMP = TEMPHEAD
          RPTR (TEMPHEAD) = TEMPHEAD
          PRV (TEMPHEAD) = NULL
          Free (TEMP)
          Return (TEMPHEAD)
3. [Save the address of the first node]
          SAVE = TEMPHEAD
4. [Search for the desire node]
          Repeat while thru step 5 RPTR (SAVE)! = NULL
5. [Check for the information field]
          If INFO (RPTR (SAVE)) = KEY
                   Then   TEMP = RPTR (SAVE)
                               RPTR (SAVE) = RPTR (RPTR (SAVE))
                               LPTR (RPTR (SAVE)) = SAVE
                               Free (TEMP)
6. [Finished]
          Return (TEMPHEAD)

Algorithm for the insert an element in the doubly list


Function INSERT (TEMPHEAD, KEY)
[This Function inserts an element after the node which the info filed equals to the KEY and the returns the address of the first node]

1. [Allocate the memory for the new node]
          NEW          NODE
          INFO (NEW) = X
2. [Insertion as the first node]
          RPTR (NEW) = TEMPHEAD
          LPTR (NEW) = NULL
          RPTR (TEMPHEAD) = NEW
          TEMPHEAD = NEW
          Return (TEMPHEAD)
3. [Save address of the first node]
          SAVE = TEMPHEAD
4. [Find the element after which we want to insert the element]
          Repeat thru step while RPTR (SAVE)! = NULL
5. [Check for the desire position]
          If INFO (RPTR (SAVE)) = KEY
                   Then
                             RPTR (NEW) = RPTR (SAVE)
                             LPTR (NEW) = SAVE
                             LPTR (RPTR (SAVE)) = NEW
                             RPTR (SAVE) = NEW
6. [Finished]
          Return (TEMPHEAD)

Algorithm for the Creation of the Doubly linked list


Procedure CRETE(TEMPHEAD)
[This Procedure Create the Doubly linked list TEMPHEAD is the pointer variable which point to the first element of the list and LPTR and RPTR is the pointer field of the NODE which points the Previous and new Node of the list respectively.]

1. [Repeat thru step]
          Repeat while choice! = ‘n’
2. [Allocate the new Node]
            NEW          NODE
3. [Set field of new Node]
          INFO (NEW) = X
          LPTR (NEW) = RPTR (RPTR) = NULL
4. [Insert the element]
          RPTR (TEMPHEAD) = NEW
          LPTR (RPTR (TEMPHEAD)) = TEMPHEAD
          TEMPHEAD = RPTR (TEMPHEAD)      
5. [Read the Choice]
          Read (choice)
6. [Finished]