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

Info iconThis 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
Background image of page 1

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

View Full DocumentRight 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
Background 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
Background image of page 3

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

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

This note was uploaded on 05/21/2010 for the course CS CS301 taught by Professor Dr.naveed malik during the Spring '10 term at Virtual University of Pakistan.

Page1 / 12

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

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online