1 / 41

List class

List class. _class Cell { void *object; Cell *next; public: ... } _class List { Cell *head; public: ... }. NULL. .head. Insert objects into a List. List class. NULL. head. .object. List class. NULL. .cell = new Cell();. head. .object. List class.

ssmiley
Télécharger la présentation

List class

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. List class _class Cell { void *object; Cell *next; public: ... } _class List { Cell *head; public: ... } NULL .head

  2. Insert objects into a List

  3. List class NULL head .object

  4. List class NULL .cell = new Cell(); head .object

  5. List class cell->next = NULL; cell->object = object; NULL .cell head NULL .object

  6. List class head = cell; .cell head NULL .object

  7. List class head NULL

  8. List class head NULL cell = new Cell(); object

  9. List class cell->next = NULL; cell->object = object; head NULL cell NULL object

  10. List class head->next = cell; head cell NULL object

  11. List class head->next = cell; head NULL

  12. Find and remove an object

  13. List class - find an object and remove it head NULL

  14. List class - find an object and remove it head if (find(head->object, object)) {... NULL

  15. List class - find an object and remove it head .ptr if (find(ptr->next->object, object)) { NULL

  16. List class - find an object and remove it head .ptr ptr = ptr->next; NULL

  17. List class - find an object and remove it head .ptr if (find(ptr->next->object, object)) { NULL

  18. List class - find an object and remove it head .ptr void *object = ptr->next->object NULL _object

  19. List class - find an object and remove it head .ptr tmp Cell *tmp = ptr->next; NULL _object

  20. List class - find an object and remove it head .ptr tmp ptr->next = ptr->next->next; NULL _object

  21. List class - find an object and remove it head .ptr tmp delete tmp; NULL _object

  22. List class - find an object and remove it head return object; NULL _object

  23. Doubly Linked Lists

  24. Doubly Linked Lists .tail head NULL

  25. Doubly Linked Lists .tail head NULL NULL

  26. Doubly Linked Lists head .tail NULL NULL

  27. Doubly Linked Lists head NULL NULL tail

  28. A Queue

  29. Circularly linked list .tail

  30. Queue: insert item at rear, remove at front .tail

  31. Queue: remove from front _object .tail void *object = tail->next->object;

  32. Queue: remove from front Temp tmp _object .tail tmp = tail->next;

  33. Queue: remove from front Temp tmp _object .tail _tail->next = tail->next->next;

  34. Queue: remove from front Temp tmp _object .tail delete tmp;

  35. Queue: remove from front Temp _object .tail _return object;

  36. Queue: remove from front Temp .tail _

  37. Queue: insert at rear Temp .tail _

  38. Queue: insert at rear _cell Temp NULL .tail _cell = new Cell(object);

  39. Queue: insert at rear _cell Temp .tail _cell->next = tail->next;

  40. Queue: insert at rear _cell Temp .tail _tail->next = cell;

  41. Queue: insert at rear _cell Temp .tail _tail = tail->next;

More Related