Data Structure (2130702)

BE | Semester-3   Winter-2016 | 01/02/2017

Q3) (b)

Write algorithm(s) to perform INSERT_FIRST (to insert a node at the first position) and REVERSE_TRAVERSE (to display the data in nodes in reverse order) operations in doubly linked list.

PRDCEDURE: DOUBINS (L, R, M, X)
1. [Create New Empty Node]
 NEW<- NODE
2. [Copy information field]
 INFO (NEW) <- X
3. [Insert into an empty list]
 If R=NULL
 then LPTR (NEW)<-RPTR(NULL) <-NULL
  L<-R<-NEW
 Return
4. [Is left most insertion ?]
 If M = L
 then LPTR (NEW)<-NULL
  RPTR (NEW) <- M
  LPTR (M)<- NEW
  L <- NEW
 Return
5. [Insert in middle]
 LPTR (NEW)<- LPTR (M)
 RPTR (NEW)<- M
 LPTR (M)<- NEW
 RPTR (LPTR (NEW))<- NEW
 Return

REVERSE_TRAVERSE