Lecture-5 (Linked List)
Lecture-5 (Linked List)
EC 200
INTRODUCTION TO LINKED LIST
Linked Lists
BOOK READINGS
Linked Lists 2
PREREQUISITE CONCEPTS
• Arrays
• Dynamic Memory
• Classes and Structures
• Deep copy
Linked Lists 3
DATA STRUCTURES
Linked Lists 4
DYNAMIC ARRAY APPLICATION
Linked Lists 5
STATIC ARRAYS: PROS AND CONS
Linked Lists 6
LINKED LIST
Linked list
Linked Lists 7
Node
Linked Lists 8
SINGLY LINKED LISTS
• A singly linked list is a
data structure consisting of next
a sequence of nodes
• Each node stores
• element elem node
• link to the next node
A B C D
Linked Lists 9
MEMORY REPRESENTATION OF LINKED
LIST & ARRAY
Linked Lists 10
BASIC OPERATIONS IN A SIMPLE
LINKED LIST:
• Insertion
• Deletion
• Searching or Iterating through the list to display
items.
Linked Lists 11
ARRAY VS LINKED LIST
Linked Lists 12
REPRESENTATION OF NODE IN C++
struct Node
{
int data; // data can be of any type
Node *next;
}
Linked Lists 13
A SIMPLE LINKED LIST CLASS
• Operations of List
• Insert / Delete
• AtStart: insert/delete a new node at start
• AtEnd: insert/delete a new node at end
• AtAnyPosition: insert/delete a new node at a particular
position
• IsEmpty: determine whether or not the list is empty
• FindNode: find a node with a given value
• Traverse: print all the nodes in the list
Linked Lists 14
REPRESENTATION OF LINKED LIST IN
C++
Class linkedList
{
// attributes
Node *head;
public:
// member functions
void insertStart(int v);
void insertEnd(int v);
void deleteStart ();
void deleteEnd();
void traverse();
linkedList();
linkedList(const linkedList& l);
~linkedList(); Linked Lists 15
INSERTING AT THE HEAD
Linked Lists 16
REMOVING AT THE HEAD
EMPTY LIST
TRAVERSING A SLL (ANIMATION)
temp
head
Linked Lists 19
COPY CONSTRUCTOR STEPS
• Audio Player
• Create a play List
• Play next Track
• Delete a track from play list
MODIFICATIONS OF LINKED LISTS
• Circular Lists
• Doubly Linked Lists
• Circular Doubly Linked Lists
Linked Lists 22
SUMMARY
Linked Lists 23
ANIMATION SOURCES
• https://www.youtube.com/watch?v=VmWvpwxa-rM
• https://www.youtube.com/watch?v=xiIoa2rfAaQ
Linked Lists 24
TEXT BOOKS
Linked Lists 25