Presentation is loading. Please wait.

Presentation is loading. Please wait.

List class.head NULL _class Cell { void *item; Cell *next; public:... } _class List { Cell *head; public:... }

Similar presentations


Presentation on theme: "List class.head NULL _class Cell { void *item; Cell *next; public:... } _class List { Cell *head; public:... }"— Presentation transcript:

1 List class.head NULL _class Cell { void *item; Cell *next; public:... } _class List { Cell *head; public:... }

2 Insert objects into a List

3 List class.head NULL.object

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

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

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

7 List class NULL.head

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

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

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

11 List class.head head->next = cell; 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 NULL If (head->item->ident == green)...

15 List class - find an object and remove it.head NULL _if (ptr->next->item->ident == green)....ptr

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

17 List class - find an object and remove it.head NULL _if (ptr->next->item->ident == green)....ptr

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

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

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

21 List class - find an object and remove it.head NULL _delete temp;.ptr _object _temp

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

23 Doubly Linked Lists

24 .head NULL.tail

25 Doubly Linked Lists.head NULL.tail

26 Doubly Linked Lists.head NULL.tail NULL

27 Doubly Linked Lists.head NULL.tail NULL

28 Lists using arrays

29 .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0.

30 .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0. Add object to front of list 1

31 .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0. Add object to front of list 1 2

32 .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0. Add object to rear of list 1 2 3

33 .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0. Add object to rear of list 1 2 34

34 .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0. Add object to front 1 2 34 5

35 .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0. 1 2 34 5 6

36 .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0. 1 2 34 5 6 Remove 3

37 .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0. 1 2 34 5 6 Remove 3

38 .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0. 1 2 34 5 6 Remove 3

39 .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0. 1 2 34 5 6 Remove 3

40 .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0. 1 2 34 5 6 Remove 3

41 .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0. 1 2 4 5 6 Remove 3

42 .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0. 1 2 4 5 6 Remove 3

43 .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0. 1 2 45 6 Remove 3

44 .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0. 1 2 45 6 Remove 3

45 .head.tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0. 1 2 45 6

46 A Queue

47 .tail Circularly linked list

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

49 .tail Queue: remove from front _object = tail->next->item; _object

50 .tail Queue: remove from front _temp = tail->next; _object TempTemp _temp

51 .tail Queue: remove from front _tail->next = tail->next->next; _object TempTemp _temp

52 .tail Queue: remove from front _delete temp; _object TempTemp _temp

53 .tail Queue: remove from front _return object; _object TempTemp

54 .tail Queue: remove from front _ TempTemp

55 .tail Queue: insert at rear _ TempTemp

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

57 .tail Queue: insert at rear _cell->next = tail->next; TempTemp _cell

58 .tail Queue: insert at rear _tail->next = cell; TempTemp _cell

59 .tail Queue: insert at rear _tail = tail->next; TempTemp _cell


Download ppt "List class.head NULL _class Cell { void *item; Cell *next; public:... } _class List { Cell *head; public:... }"

Similar presentations


Ads by Google