1 / 13

Linked List Lesson xx

Linked List Lesson xx. Objectives. Linked list concept Node structure Creating a static linked list Accessing items in a linked list. Illustration of a Linked List. Head. a. b. c. d. e 0. Linked List Program. #include < iostream > using std:: cout ; using std:: endl ;

celina
Download Presentation

Linked List Lesson xx

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. Linked ListLesson xx

  2. Objectives • Linked list concept • Node structure • Creating a static linked list • Accessing items in a linked list

  3. Illustration of a Linked List Head a b c d e 0

  4. Linked List Program #include <iostream> using std::cout; using std::endl; struct entry { int value;   entry* next; }; int main() {   entry n1, n2, n3;   n1.value = 100;   n2.value = 200;   n3.value = 300;   n1.next = &n2;   n2.next = &n3; cout << n1.value << “ “ << n1.next << endl; cout << n1.next->value << endl; // cout <<(*n1.next).value ;cout << n1.next->next->value << endl ;   cout << n2.next->value << endl ;  return 0; }

  5. Node Structure struct entry { int value;   entry* next; }; .value .next

  6. Node Declaration entry n1, n2, n3; n1 n2 n3 n1.value n2.value n3.value n1.next n2.next n3.next

  7. Node Initialization n1.value = 100;   n2.value = 200;   n3.value = 300; n2 n3 n1 200 300 100 n2.value n3.value n2.next n3.next n1.value n1.next

  8. Connecting Nodes   n1.next = &n2;   n2.next = &n3; n2 n3 (7fa) (88b) n1 (56c) 88b 200 300 100 7fa n2.value n3.value n2.next n3.next n1.value n1.next

  9. Different Explanation   n1.next = &n2;   n2.next = &n3; n2 n3 n1 200 300 100 n2.value n3.value n2.next n3.next n1.value n1.next

  10. Print Contents of First Node cout << n1.value << “ “ << n1.next; << endl; n2 n3 (7fa) (88b) n1 (56c) 88b 200 300 100 7fa n2.value n3.value n2.next n3.next n1.value n1.next

  11. Print Value of 3rd Node cout << n2.next->value << endl ; n2 n3 (7fa) (88b) n1 (56c) 88b 200 300 100 7fa n2.value n3.value n2.next n3.next n1.value n1.next

  12. Print Value of 3rd Node Different Syntax cout << n1.next->next->value; n2 n3 (7fa) (88b) n1 (56c) 88b 200 300 100 7fa n2.value n3.value n2.next n3.next n1.value n1.next

  13. Summary • Linked list concept • Node structure • Creating a static linked list • Accessing items in a linked list

More Related