Escolar Documentos
Profissional Documentos
Cultura Documentos
The one way linked list gives us the facility of accessing the list in just one direction. The two way linked list gives us the facility of accessing the list in two direction that is in forward and in backward direction. In this each node consist of three nodes: 1. The Right pointer(RP): which keeps the address of successor node. 2. Left pointer (LP): which keeps the address of predecessor node. 3. Information Field (INFO): which keeps the data of the node. Double Linked array has two pointers: HEAD : keeps the address of the first node. TAIL: Keeps the address of last node.
Starting from HEAD and following RP ,we can traverse the list in forward direction. Similarly starting from TAIL and following LP,we can traverse the list in backward direction. The first nodes LP and last nodes RP are nil,because there is no node on the left side of 1st node and on the right of the last node.
Traversing Algorithm
Algorithm: Forward Set a pointer to the HEAD P:= Head Set a loop while (P Nil) Loop start 1. Process the node , INFO(P) 2. Go forward , P:= RP(P) End of Loop Algorithm: Forward traversing 3. Exit
Backward Traversing
Algorithm: Backward traversing 1. Set a pointer to the TAIL , P:= TAIL 2. Set a LOOP, While (p Nil) Loop start 1. Process the node, INFO(P) 2. Go backward P:= LP(P) End of Loop 3. EXIT
Searching Algorithm
To search a particular node in double linked list we need an information KEY with which we will compare the INFO Field of all nodes. -- Forward searching -- Backward searching
Forward searching
Algorithm: Forward searching 1. Set a pointer to the HEAD P:= HEAD 2. Set a loop, while (INFO(P) Key) and (P nil) 3. Go forward P:= RP(P) End of loop 4. If p = Nil then Write : Search unsuccessful ELSE Write : search Successful 5. EXIT.
Backward searching
ASSIGGNMENT to be solved the class
Insertion
Insertion before a given node Insertion after a given node.
Continue
If( P!= Nil and R= Nil) then i. TAIL:= P ii. RP(P):= R Else i. RP(P ):= R ii. LP(R ) := P 3.Remove the Node Q Delete Q 4. Exit
Searching
1. 2. 3. Algorithm: This algorithm search for information KEY. P:= HEAD FOUND:= FALSE Repeat If INFO(P) = Key Then Found:= True Else P:= LINK(P) Until (P= HEAD) Or (FOUND) 4. If Found , write: search successful Else Write:Search unsuccessful 5. Exit