1 / 15

Data Structure

Data Structure . Ali Abdul Karem Habib MSc.IT. Doubly Linked List . A doubly linked list is a collection of data elements, called nodes, where each node N is divided into 3 parts. INFO field which contains the data NEXT field which contains the location of the next node

erol
Download Presentation

Data Structure

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Structure Ali Abdul KaremHabib MSc.IT

  2. Doubly Linked List • A doubly linked list is a collection of data elements, called nodes, where each node N is divided into 3 parts. • INFO field which contains the data • NEXT field which contains the location of the next node • PREV field which contains the location of previous node in the list. • The pointer PTR[PREV] of the first node and PTR[NEXT] of the last node is NULL • In DLL can traverse from front and back and this reduce time to insert and delete . Data Next Prev

  3. Operation On Doubly Linked List • 1- Create DLL • 2- Insertion • At First • At Last • At Any Position • 3- Deletion • At First • At Last • At Any Position 4- Traversing :- • From Start • From Last 5- Searching

  4. Create DLL Node Using C++ • structDnode • { • Data type Value ; • Dnode * next , *prev ; • }

  5. Algorithm Of Create First NODE • 1- Start • 2- If Start=Null then • 3- Prepare DNode • 4- Read data • 5- DNode ->data= data • 6- DNode ->next=Null7-Dnode->prev=Null • 8- Start = DNode • 9- Cur = DNode • 10- End .

  6. Algorithm Insertion At First • Start • 2- Prepare DNode • 3- Read Data • 4- DNode ->Data=Data • 5- DNode->next=Start • 6- Dnode->Prev=Null • 7- start->prev=node • 8- Start=DNode • 9-End.

  7. Insertion At Last • 1- Start • 2- 1- Start • 2- Prepare DNode • 3- Read Data • 4- DNode ->Data=Data • 5- Dnode->Prev=Cur • 6- Cur->next=DNode • 7- Cur=node • 8- Cur ->next=Null • 9- End

  8. Insert At Any Position • 1- Start • 2- Prepare DNode • 3- Read Data • 4- Read Pos • 5- DNode -> Data=Data • 6- temp =start • 7- Let Cn=1 • 8- while( Cn < pos-1) • 9- temp=temp-> next • 10- Cn=Cn+1 • 11- End While • 12- DNode -> next=temp ->next • 13- temp ->next->Prev=DNode • 14- temp->Next=Dnode • 15- Node->Prev=temp • 14- End

  9. Delete First • 1-Start • 2- temp=Start • 3- Start= Start -> next • 4- Start->Prev=Null • 5- Delete ( temp ) • 6- temp=Null • 7- End .

  10. Delete At Last • 1- Start • 2- Let Temp=Curr • 3- Cur=Cur->Prev • 4- Cur->Next=Null • 5- Delete(temp) • 6- Temp=Null • 7- End

  11. Deletion From Any Position 1- Start 2- Let Temp=start 3- Read Pos 4- Cn=1 5- while ( Cn< pos) 6- temp=temp -> next 7- Cn=Cn+1 8- End While 9- P= temp 10- temp->next->Prev =temp->Prev 11-temp->Prev->Next=temp->Next 11- Delete (p) 12- p=null 13- end

  12. Traversing From Start • 1- Start • 2- temp=start • 3- While ( temp <> null ) • 4- print (temp -> Data ) • 5- temp = temp -> next • 6- End while • 7- End .

  13. Travers From Last • 1- Start • 2- temp=Cur • 3- While ( temp <> null ) • 4- print (temp -> Data ) • 5- temp = temp -> Prev • 6- End while • 7- End .

  14. Searching 1- Start 2- let temp=start 3- Read key 4- While ( temp <> null) 5- If ( temp -> Data = key ) then 6- print ( “ Found “) 7- else Print ( “Not Found “ ) 8- temp = temp -> next ) 9- End While 10 - End

  15. Assignment • Implement Queue Using DLL

More Related