List class NULL class Cell void object Cell
List class NULL _class Cell { void *object; Cell *next; . head } public: . . . _class List { Cell *head; } public: . . .
Insert objects into a List
List class NULL head . object
List class NULL . cell = new Cell(); head . object
List class NULL cell->next = NULL; cell->object = object; . cell head NULL . object
List class head = cell; . cell head NULL . object
List class head NULL
List class head NULL cell = new Cell(); object
List class head cell->next = NULL; cell->object = object; NULL cell NULL object
List class head->next = cell; head cell NULL object
List class head->next = cell; head NULL
Find and remove an object
List class - find an object and remove it head NULL
List class - find an object and remove it head if (find(head->object, object)) {. . . NULL
List class - find an object and remove it head . ptr if (find(ptr->next->object, object)) { NULL
List class - find an object and remove it head . ptr = ptr->next; NULL
List class - find an object and remove it head . ptr if (find(ptr->next->object, object)) { NULL
List class - find an object and remove it head . ptr void *object = ptr->next->object NULL _object
List class - find an object and remove it head . ptr Cell *tmp = ptr->next; tmp NULL _object
List class - find an object and remove it head . ptr->next = ptr->next; tmp NULL _object
List class - find an object and remove it head . ptr delete tmp; tmp NULL _object
List class - find an object and remove it head return object; NULL _object
Doubly Linked Lists
Doubly Linked Lists head NULL . tail
Doubly Linked Lists head NULL . tail NULL
Doubly Linked Lists head . tail NULL
Doubly Linked Lists head NULL tail
A Queue
Circularly linked list . tail
Queue: insert item at rear, remove at front . tail
Queue: remove from front _object . tail void *object = tail->next->object;
Queue: remove from front T e m p tmp _object . tail tmp = tail->next;
Queue: remove from front T e m p tmp _object . tail _tail->next = tail->next;
Queue: remove from front T e m p tmp _object . tail delete tmp;
Queue: remove from front T e m p _object . tail _return object;
Queue: remove from front T e m p . tail _
Queue: insert at rear T e m p . tail _
Queue: insert at rear _cell T e m p NULL . tail _cell = new Cell(object);
Queue: insert at rear _cell T e m p . tail _cell->next = tail->next;
Queue: insert at rear _cell T e m p . tail _tail->next = cell;
Queue: insert at rear T e m p _tail = tail->next; _cell . tail
- Slides: 41