1 / 27

Linked List (2)

Linked List (2). Sanchai Yeewiyom School of Information & Communication Technology University of Phayao. Linked List Deletion. 3 methods Deleting a specified node from a linked list. Deletion of the first node in a linked list. Deletion of the last node in a linked list. 5. 8. 10.

albertmoore
Download Presentation

Linked List (2)

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. Linked List (2) Sanchai Yeewiyom School of Information & Communication Technology University of Phayao

  2. Linked List Deletion • 3 methods • Deleting a specified node from a linked list. • Deletion of the first node in a linked list. • Deletion of the last node in a linked list.

  3. 5 8 10 Deleting a specified node from a linked list. 1 head prev cur

  4. Deleting a specified node from a linked list. • Algorithm prev -> next = cur -> next; delete cure; cur = null;

  5. 5 8 10 Deletion of the first node in a linked list. 1 head cur

  6. Deletion of the first node in a linked list. • Algorithm cur = head; head = head -> next; delete cure; cur = null;

  7. 5 8 10 Deletion of the last node in a linked list. 1 head prev cur

  8. Deletion of the last node in a linked list. • Algorithm prev -> next = cur -> next; delete cur; cur = null;

  9. Conclude of Deletion • Deletion at the first node of a list. • Deletion at the last node or any node of a list.

  10. Exp. Deletion void deletion(int val) { prev = null; cur = head; while (cur != null && val != cur->data) { prev = cur; cur = cur->next; } if cur = = null { cout << “not found” << endl; } else { if prev = = null { head = head->next; } else { prev->next = cur->next; cur->next = null; } delete cur; cur = null; } }

  11. 10 5 8 Circular Linked List

  12. Circular Linked List • Principle • เริ่มต้นให้ list = null • สร้าง list ใหม่ • ให้ list ย้ายไปชี้ที่ตัวที่สร้างใหม่ (ตัวสุดท้าย)

  13. Circular Linked List • Picture

  14. Circular Linked List • Homework จงเขียน Function ของการ Delete Node ออกจาก Circular Linked List โดยกำหนดให้มีการรับค่าที่ต้องการลบเข้ามา จากนั้นทำการค้นหา เมื่อเจอ Node ที่ต้องการให้ทำการลบ Node นั้นออกไป

  15. Doubly Linked List • A linked list that have 2 pointers (front, end)

  16. Doubly Linked List data next precede

  17. Doubly Linked List struct node; typedef node *ptrtype; struct node { int data; ptrtype precede, next; };

  18. Insertion of Doubly Linked List • Picture

  19. Insertion of Doubly Linked List • Algorithms newptr -> next = cur; newptr -> precede = cur -> precede; (cur -> precede) -> next = newptr; cur -> precede =newptr;

  20. Deletion of Doubly Linked List • Picture

  21. Deletion of Doubly Linked List • Algorithms (cur -> precede) -> next = cur -> next; (cur -> next) -> precede = cur -> precede;

  22. Circular Doubly Linked List • เหมือนกับ CLL ทำงานเหมือนกัน • ต้องมี Dummy Head Node -999 listhead

  23. Circular Doubly Linked List • สร้าง Dummy Head Node listhead = new node; listhead->data = -999; listhead->precede = listhead; listhead->next = listhead;

  24. Insertion of Circular Doubly Linked List • Picture

  25. Insertion of Circular Doubly Linked List • Algorithm

  26. Deletion of Circular Doubly Linked List • Picture

  27. Deletion of Circular Doubly Linked List • Algorithm

More Related