View
227
Download
0
Tags:
Embed Size (px)
Citation preview
List class
.head
NULL_class Cell { void *object; Cell *next;
public: ... }
_class List { Cell *head;
public: ... }
Insert objects into a List
List class
.object
NULL
head
List class
.object
.cell = new Cell();NULL
head
List class
NULL
.object
.cell
cell->next = NULL;cell->object = object;
NULL head
List class
.object
.cell
head = cell;
NULL head
List class
head NULL
List class
NULL
cell = new Cell();
object
head
List class
NULL
cell
head
cell->next = NULL;cell->object = object;
object
NULL
List class head->next = cell;
NULL
cell
object
head
List class
head->next = cell;
NULL
head
Find and remove an object
List class - find an object and remove it head
NULL
List class - find an object and remove it
NULL
if (find(head->object, object)) {...
head
List class - find an object and remove it
NULL
if (find(ptr->next->object, object)) {
.ptr
head
List class - find an object and remove it
NULL
ptr = ptr->next;
.ptr
head
List class - find an object and remove it
NULL
if (find(ptr->next->object, object)) {
.ptr
head
List class - find an object and remove it
NULL
void *object = ptr->next->object
_object
head
.ptr
List class - find an object and remove it
NULL
Cell *tmp = ptr->next;
.ptr
_object
tmp
head
List class - find an object and remove it
NULL
ptr->next = ptr->next->next;
_object
tmp
head
.ptr
List class - find an object and remove it
NULL
delete tmp;
_object
tmp
head
.ptr
List class - find an object and remove it
NULL
return object;
_object
head
Doubly Linked Lists
Doubly Linked Lists
headNULL
.tail
Doubly Linked Lists
head
NULLNULL
.tail
Doubly Linked Lists
head
NULL
.tail
NULL
Doubly Linked Lists
head
NULL
tail
NULL
A Queue
.tail
Circularly linked list
.tail
Queue: insert item at rear, remove at front
.tail
Queue: remove from front
void *object = tail->next->object;
_object
.tail
Queue: remove from front
tmp = tail->next;
_object
Temp
tmp
.tail
Queue: remove from front
_tail->next = tail->next->next;
_object
Temp
tmp
.tail
Queue: remove from front
delete tmp;
_object
Temp
tmp
.tail
Queue: remove from front
_return object;
_object
Temp
.tail
Queue: remove from front
_
Temp
.tail
Queue: insert at rear
_
Temp
.tail
Queue: insert at rear
_cell = new Cell(object);
Temp
_cell
NULL
.tail
Queue: insert at rear
_cell->next = tail->next;
Temp
_cell
.tail
Queue: insert at rear
_tail->next = cell;
Temp
_cell
.tail
Queue: insert at rear
_tail = tail->next;
Temp
_cell