{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CS301-Lec03 handout - CS301 Data Structures Lecture No 03...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CS301 – Data Structures Lecture No. 03 ___________________________________________________________________ Data Structures Lecture No. 03 Reading Material Data Structures and algorithm analysis in C++ Chapter. 3 3.2.2, 3.2.3, 3.2.5 Summary Linked List inside Computer Memory Linked List Operations Linked List Using C++ Example Program In the previous lectures, we used an array to construct a list data structure and observed the limitation that array being of fixed size can only store a fixed number of elements. Therefore, no more elements can be stored after the size of the array is reached. In order to resolve this, we adopted a new data structure called linked list. We started discussing, how linked lists are stored in computer memory and how memory chains are formed. Page 1 of 12
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS301 – Data Structures Lecture No. 03 ___________________________________________________________________ Linked List inside Computer Memory Fig 1. Linked list in memory There are two parts of this figure. On the left is the linked list chain that is actually the conceptual view of the linked list and on the right is the linked list inside the computer memory. Right part is a snapshot of the computer memory with memory addresses from 1051 to 1065 . The head pointer is pointing to the first element in the linked list. Note that head itself is present in the memory at address 1062. It is actually a pointer containing the memory address 1054 . Each node in the above linked list has two parts i.e. the data part of the node and the pointer to the next node. The first node of the linked list pointed by the head pointer is stored at memory address 1054. We can see the data element 2 present at that address. The second part of the first node contains the memory address 1051 . So the second linked list’s node starts at memory address 1051 . We can use its pointer part to reach the third node of the list and in this way, we can traverse the whole list. The last node contains 1 in its data part and 0 in its pointer part. 0 indicates that it is not pointing to any node and it is the last node of the linked list. Linked List Operations The linked list data structure provides operations to work on the nodes inside the list. The first operation we are going to discuss here is to create a new node in the memory. The Add(9) is used to create a new node in the memory at the current Page 2 of 12 6 1051 1063 1052 1063 1053 2 1054 1051 1055 1056 7 1057 1060 1058 1059 1 1060 0 1061 1054 1062 8 1063 1057 1064 1065 current ent head ent head 2 6 8 7 1
Image of page 2
CS301 – Data Structures Lecture No. 03 ___________________________________________________________________ position to hold ‘ 9 ’. You must remember while working with arrays, to add an element at the current position that all the elements after the current position were shifted to the right and then the element was added to the empty slot. Here, we are talking about the internal representation of the list using linked list. Its interface will remain the same as in case of arrays.
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern