Download presentation
Presentation is loading. Please wait.
Published byTracey Paul Modified over 8 years ago
3
Review building a complete linked list List traversal in main ( ) List traversal using a function
4
struct entry { int value; entry* next; }; int main() { entry n1, n2, n3; entry* head = &n1; n1.next = &n2; n2.next = &n3; n3.next = 0; n1.value = 100; n2.value = 200; n3.value = 300; entry * temp; temp= head; // traverse the list while (temp != NULL) { cout value next << endl; temp = temp->next; } return 0; }
5
entry n1, n2, n3; entry* head = &n1; n1.next = &n2; n2.next = &n3; n3.next = 0; n1.value = 100; n2.value = 200; n3.value = 300; n1 n1.valuen1.next n2 n2.valuen2.next n3 n3.valuen3.next 100 200300 (56c) (7fa)(88b) 7fa 88b 0 56c head
6
n1 n1.valuen1.next n2 n2.valuen2.next n3 n3.valuen3.next 100 200300 (56c) (7fa)(88b) 7fa 88b 0 56c head 56c temp entry * temp; temp= head;
7
n1 n1.valuen1.next n2 n2.valuen2.next n3 n3.valuen3.next 100 200300 (56c) (7fa)(88b) 7fa 88b 0 56c head 56c temp while (temp != NULL) { cout value next << endl; temp = temp->next; }
8
n1 n1.valuen1.next n2 n2.valuen2.next n3 n3.valuen3.next 100 200300 (56c) (7fa)(88b) 7fa 88b 0 56c head 56c temp 56c 100 7fa temp temp->value temp->next
9
temp = temp->next; n1 n1.valuen1.next n2 n2.valuen2.next n3 n3.valuen3.next 100 200300 (56c) (7fa)(88b) 7fa 88b 0 56c head 7fa temp
10
while (temp != NULL) { cout value next << endl; temp = temp->next; } n1 n1.valuen1.next n2 n2.valuen2.next n3 n3.valuen3.next 100 200300 (56c) (7fa)(88b) 7fa 88b 0 56c head 7fa temp
11
56c 100 7fa 7fa 200 88b 88b 300 0 n1 n1.valuen1.next n2 n2.valuen2.next n3 n3.valuen3.next 100 200300 (56c) (7fa)(88b) 7fa 88b 0 56c head 0 temp
12
struct entry { int value; entry* next; }; void printList(const entry*); // prototype int main() { entry n1, n2, n3; n1.next = &n2; n2.next = &n3; n3.next = 0; entry* head = &n1; printList(head); return 0; } void printList(const entry* pointer) { while (pointer != 0 ) { cout value next << endl; pointer = pointer->next; } }
13
struct entry { int value; entry* next; }; void printList(const entry*); // prototype int main() { entry n1, n2, n3; n1.next = &n2; n2.next = &n3; n3.next = 0; entry* head = &n1; printList(head); return 0; } void printList(const entry* pointer) { while (pointer != 0 ) { cout value next << endl; pointer = pointer->next; } } 1 2 3
14
n1 n1.valuen1.next n2 n2.valuen2.next n3 n3.valuen3.next 100 200300 (56c) (7fa)(88b) 7fa 88b 0 56c head 56c pointer void printList(const entry* pointer) { while (pointer != 0 ) { cout value next << endl; pointer = pointer->next; } }
15
Building a complete linked list List traversal in main ( ) List traversal using a function
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.