{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

LinkedLists01 - Linked List Linked List The simplest form...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Linked List Linked List: The simplest form of a linked structure. It consists of a chain of data locations called nodes. Each node holds a piece of information AND a link to the next node. We can think of each node as a record. The first part of the record is a field that stores the data, and the second part of the record is a field that stores a pointer to a node. Here is a picture of what a simple linked list that stores Num values looks like: Here is a struct we would use to define a record that stores one of these nodes: struct ll { int data; struct ll *next; } Now, to actually use this record we would have to define a variable of type ll as follows: struct ll *my_list;
Background image of page 1

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

View Full Document Right Arrow Icon
How to access nodes of a linked list Let’s assume we already have my_list initialized to look like this: (Don’t worry how this occurred, we’ll go through that in a bit.) Now, one of the most common errors dealing with pointers is “moving” the head of the list. Consider if we made my_list point to the second node we have listed. In this case, we would have NO way to access that data value in the first record.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}