Sunteți pe pagina 1din 5

Algorithm InsertFront_DL Step1:ptr=HEADER->RLINK Step2:new=GetNode(NODE) Step3:if(new!

=NULL)then Step4:new->LLINK=HEADER //points to the first node //avail a new node from the memory bank //if new node is available //newly inserted node points the header

Step5:HEADER->RLINK=new //header now points to the new node Step6:new->RLINK=ptr Step7:ptr->LLINK=new Step8:new->DATA->X Step9:Else Step10:PrintUnable to allocate memory:Insertion is not possible Step11:EndIf Step12:stop //copy the data into the newly inserted node

INSERTING A NODE AT THE END Step1: Ptr=HEADER Step2: While(ptr->RLINK!=NULL)do Step3: Ptr=ptr->RLINK Step4: EndWhile Step5: New=GetNode(NODE) Step6: If(new!=NULL)then Step7:New->LLINK=ptr Step8: Ptr->RLINK=new Step9: New->RLINK=NULL //make the new node as the last node //avail a new node //if the node is available //move to the last node

Step10: New->DATA=X Step11: Else

//copy the data into the new node

Step12: Print Unable to allocate memory:Insertion is not possible Step13: Endif Step14: stop

ALGORITHM INSERTANY_DL Step1: : Ptr=HEADER Step2: While(ptr->DATA!=KEY)and(ptr->RLINK!=NULL) //move the //key node if the current node is not the KEY node or if the list reaches the end Step3:ptr=ptr->RLINK Step4:EndWhile Step5:new=GetNode(NODE) //storage Step6:If(new=NULL)then //Get a new node from the pool of free //when memory is not available

Step7:Print(memory is not available) Step8:Exit Step9:End if Step10:If(ptr->RLINK=NULL)then the //list Step11:new->LLINK=ptr Step12:ptr->RLINK=new Step13:new->RLINK=NULL Step14: New->DATA=X //copy the data into the new node //insert at the end //if the KEY is not found in //quit the program

Step15: : Else

//the KEY is available //next node after the key node

Step16: ptr1=ptr->RLINK Step17: new->LLINK=ptr Step18: new->RLINK=ptr1 Step19:ptr->RLINK=new Step20: ptr1->LLINK=new Step21:ptr=new Step22: New->DATA=X Step23:EndIf Step24:stop

//this becomes the current node //copy the content to the newly inserted node

ALGORITHM DELETEFRONT_DL Step1:HEADER ->RLINK Step2:If(ptr=NULL)then //pointer to the first node //if the list is empty

Step3:print list is empty:no deletion is made Step4:exit Step5:else Step6:ptr1=ptr->RLINK Step7:HEADER->RLINK=ptr1 Step8:If(ptr1!=NULL) //node of deletion Step10:end if Step11:return node (ptr) Step12: end if //return the deleted node the memory bank //if the list contain a node after the first //pointer to the second node

Step13:stop

Algorithm DeleteEnd_DL Step1:ptr=HEADER Step2:While(ptr->RLINK!=NULL)do Step3:ptr=ptr->RLINK Step4:EndWhile Step5:If(ptr=HEADER)Then //if the list is empty //move to the last node

Step6:Print list is empty:No deletion is made Step7:exit Step8:Else Step9:ptr1=ptr->LLINK Step10:ptr1->RLINK=NULL Step11:Return Node(ptr) the //memory bank Step12:EndIf Step13:stop //return the deleted node to //Pointer to the last but one node //Quit the program

Step1:ptr=HEADER->RLINK Step2:If(ptr=NULL)then

//Move to the first node

Step3:Print List is empty:No deletion is made Step4:Exit Step5EndIf //Quit the program

Step6:While(ptr->DATA!=KEY)and(ptr->RLINK!=NULL)do to //the desired node Step7:ptr=ptr->RLINK Step8:EndWhile Step9:If(ptr->DATA=KEY)then Step10:ptr1=ptr->LLINK Step11:ptr2=ptr->RLINK Step12:ptr1->RLINK=ptr2 Step13:If(ptr2!=NULL)then Step14:ptr2->RLINK=ptr1 Step15:EndIf Step16:Return node(ptr) Step17:Else Step18:print The node does not exist in the given node Step19:EndIf Step20:stop //if the deleted node is last node //If the node is found

//Move

//Track the predecessor node //Track the successor node

//Return the free node to the memory bank

S-ar putea să vă placă și