









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Lecture 09: Data Structures - Linked Lists
Anum Tariq
(Lecturer)
Date: May 05, 2020
Linked lists
Variations of linked lists
Head
A
data pointer
node
Each node contains at least
A piece of data (any type)
pointer of the current node is equal to the head.)
A
Head
B C
distinct advantages.
in memory as needed.
variables to make room for new elements or close the gap caused by deleted
elements.
pointers.
struct.
processed.
node type itself.
current = head; copies the value of head into current
Now consider the statement: current = current->link;
with linked lists, we typically use these types of statements to advance a pointer to the next node in the
list.)
current = head;
while (current != NULL)
cout << current->info << " ";
current = current->link;
class Node {
public:
double data; // data
Node* next; // pointer to next
DeleteNode: delete a node with a given value
void List::DisplayList()
{
int num = 0;
Node* currNode = head;
while (currNode != NULL)
{
cout << currNode->data << endl;
currNode = currNode->next;
num++;
}
cout << "Number of nodes in the list: " << num << endl;
}