SlideShare a Scribd company logo
Placement Preparation 
Linked List 
Shobhit Chaurasia 
B.Tech, CSE
Target Audience 
People who have coding experience limited to the basic 
syntax of C++, pointers and structures, but didn’t take 
CS101 seriously and want to learn some basics of coding 
quickly. 
If you already know how to implement a linked list, then 
please spare me the pain of taking a lecture on linked 
lists, and volunteer to deliver this lecture.
Motivation 
Suppose I have an array: 1,4,10,19,6 
I want to insert a 7 between the 4 and the 10 
What do we need to do?
Linked List 
head
Node
How to represent a Node in C++ ? 
How to represnt integers in C++? 
int x; 
But Node is a combination of data + pointer 
(int) + pointer 
(char) + pointer 
(string) + pointer
Structures Revisited 
Structure variable 
stud s; 
Access members of struct 
; 
s.rollNo = 11010179 
s.cpi = 8.1 
s.gender = ‘M’
How to represent Node in C++ 
;
Head 
Pointer to the first node. 
Holds the address of the first node in the list 
head
Head 
Pointer to the first node. 
node* head 
;
Struct Pointer revisited 
Struct Pointer 
stud *s; 
Access members of struct 
s->rollNo = 11010179 
s->cpi = 8.1 
s->gender = ‘M’ 
rollNo cpi gender 
s 
;
Accessing data/next node 
node* head 
Data stored at first node 
head->data = ‘a’; 
Pointer to second node 
head->next 
Data stored at second node 
(head->next)->data = ‘b’; 
head 
;
Demo #0(a) 
node* temp; 
temp = head; 
cout<<temp->data; 
head
Demo #0(a) 
How to go to the second node? 
temp = temp->next; 
cout<<temp->data; 
head
Demo #0(a) 
How to go to the third node? 
temp = temp->next; 
cout<<temp->data; 
head
Where’s the list’s end? 
head 
ptr
Demo #0(b) 
Printing the linked list
Demo #0(b) 
Printing the linked list (correct version)
Demo #0(b) 
An observation
Demo #0(b) - MORAL 
Never move the HEAD while traversing a 
linked list
Demo #1 
Function to print the 3rd element in linked list
Insert a new node at the end 
node* temp; 
temp = start; 
temp->next == NULL ??
Insert a new node at the end 
temp = temp->next; 
temp->next == NULL ??
Insert a new node at the end 
temp = temp->next; 
temp->next == NULL ??
Insert a new node at the end 
temp = temp->next; 
temp->next == NULL ??
Insert a new node at the end 
temp = temp->next; 
temp->next == NULL ?? (YES!! Finally reached the end)
Insert a new node at the end 
node* ptr = new node 
ptr
Insert a new node at the end 
ptr 
ptr->data = ‘f’; 
ptr->next = NULL; 
f
Insert a new node at the end 
ptr 
temp->next = ptr;
Demo #2 
Inserting a new node at the end. 
Discuss 2.cpp
Insert a new node at the start 
node* ptr = new node; 
ptr
Insert a new node at the start 
node* ptr = new node; 
ptr->data = ‘z’; 
z ptr
Insert a new node at the start 
ptr->next = start; 
ptr
Insert a new node at the start 
start = ptr; 
ptr
Demo #3 
Insert a new node at the head 
Discuss 3.cpp (two methods)
Demo #4 
Create a linked list and print its contents.
Demo #5 
Same as last problem. Use functions.
Insert after a particular node
Demo #6 
Write a function which takes as parameter a 
node pointer and inserts a new node after it. 
insertInBetween (node* temp)
Deleting first node
Deleting first node
ACTUALLY Deleting first node
ACTUALLY Deleting first node
ACTUALLY deleting first node
ACTUALLY deleting first node 
delete frees the memory allocated by new
Demo #7 
Write a function to delete the first node of a 
linked list. 
Add this function to 5.cpp
Demo #8 
Write a function to delete the last node of 
linked list 
Add this function to 7.cpp
Delete a node inside the linked list
Delete a node inside the linked list
Locating the node “y”
Can we delete the node “y” now? 
Having just the pointer to the node containing 
“y” sufficient to delete it?
What do we want to do? 
Break this link, and make it point to the 
node “d”
Expected Output
What do we need? 
Pointer to the previous node
Step 1 
prev->next = temp->next;
Step 2 
delete temp;
Final output
Demo #9 
Delete the node with data = 3 
Add this function to 5.cpp
Homework 
Reverse a linked list.
Linked list vs Arrays 
Operation Linked List Array 
Insert at start O(1) O(n) 
Insert anywhere O(1) O(n) 
Delete anywhere O(1) O(n) 
Access ith element O(n) O(1)
THANK YOU

More Related Content

What's hot (20)

PPTX
Pointer in c program
Rumman Ansari
 
PPT
Chapter 11 - Sorting and Searching
Eduardo Bergavera
 
PPTX
POLYNOMIAL ADDITION USING LINKED LIST.pptx
AdarshRaj244539
 
PPTX
Data structure tree - intermediate
MD. MARUFUZZAMAN .
 
PPT
Chapter 6. Mining Frequent Patterns, Associations and Correlations Basic Conc...
Subrata Kumer Paul
 
PPTX
Three dimensional graphics package.N.kavitha.pptx
ComputerScienceDepar6
 
PPT
Heaps
Hafiz Atif Amin
 
PPTX
linked list in Data Structure, Simple and Easy Tutorial
Afzal Badshah
 
PPT
Binary search tree in data structures
chauhankapil
 
PPTX
Array ppt
Kaushal Mehta
 
PPTX
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
PPTX
Linklist
SHEETAL WAGHMARE
 
PPT
Lec 17 heap data structure
Sajid Marwat
 
PPTX
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
widespreadpromotion
 
PPTX
Introduction to ip addressing by kalyan kk
kalyan kumar
 
PPTX
Searching and sorting
PoojithaBollikonda
 
PPTX
My lectures circular queue
Senthil Kumar
 
PPT
Data Structure: TREES
TABISH HAMID
 
PPTX
Tree in data structure
ghhgj jhgh
 
PPTX
Data structures
MADHAVASAIYENDUVA
 
Pointer in c program
Rumman Ansari
 
Chapter 11 - Sorting and Searching
Eduardo Bergavera
 
POLYNOMIAL ADDITION USING LINKED LIST.pptx
AdarshRaj244539
 
Data structure tree - intermediate
MD. MARUFUZZAMAN .
 
Chapter 6. Mining Frequent Patterns, Associations and Correlations Basic Conc...
Subrata Kumer Paul
 
Three dimensional graphics package.N.kavitha.pptx
ComputerScienceDepar6
 
linked list in Data Structure, Simple and Easy Tutorial
Afzal Badshah
 
Binary search tree in data structures
chauhankapil
 
Array ppt
Kaushal Mehta
 
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
Lec 17 heap data structure
Sajid Marwat
 
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
widespreadpromotion
 
Introduction to ip addressing by kalyan kk
kalyan kumar
 
Searching and sorting
PoojithaBollikonda
 
My lectures circular queue
Senthil Kumar
 
Data Structure: TREES
TABISH HAMID
 
Tree in data structure
ghhgj jhgh
 
Data structures
MADHAVASAIYENDUVA
 

Viewers also liked (10)

PPTX
Linked list
Lovelyn Rose
 
PPTX
Linked List data structure
Marcus Biel
 
PPTX
Linked list
Md. Afif Al Mamun
 
PPT
Linked lists
GowriKumar Chandramouli
 
PPTX
Array implementation and linked list as datat structure
Tushar Aneyrao
 
PPTX
linked list
Mohaimin Rahat
 
PPT
Link List
umiekalsum
 
PPT
Linked list
Trupti Agrawal
 
PPTX
Linked list
akshat360
 
PPTX
Link list
Syeda Javeria
 
Linked list
Lovelyn Rose
 
Linked List data structure
Marcus Biel
 
Linked list
Md. Afif Al Mamun
 
Array implementation and linked list as datat structure
Tushar Aneyrao
 
linked list
Mohaimin Rahat
 
Link List
umiekalsum
 
Linked list
Trupti Agrawal
 
Linked list
akshat360
 
Link list
Syeda Javeria
 
Ad

Similar to Lecture 6: linked list (20)

PPTX
Linked lists
Eleonora Ciceri
 
PPT
dynamicList.ppt
ssuser0be977
 
PPTX
singlelinkedlistasdfghzxcvbnmqwertyuiopa
rabailasghar3
 
PPTX
DS_LinkedList.pptx
msohail37
 
PPTX
Lec3-Linked list.pptx
FaheemMahmood2
 
PPTX
Linked lists a
Khuram Shahzad
 
PPTX
linked list
Ayesha Sajjad
 
PPTX
linked list_MODULE 3.pptx ppt on the linked list
AnuragKumar682871
 
PPT
Link list part 1
Anaya Zafar
 
PPT
linkedlistwith animations.ppt
MuhammadShafi89
 
PPTX
UNIT 2LINKEDLISdddddddddddddddddddddddddddT.pptx
shesnasuneer
 
PPTX
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
PPTX
linkedlist-130914084342-phpapp02.pptx
MeghaKulkarni27
 
DOCX
Linked List
BHARATH KUMAR
 
PDF
Cpp lernaufgabe linked_list
Ibrahim El-Torbany
 
PDF
DS Module 03.pdf
SonaPathak5
 
PPTX
Linear data structure concepts
Akila Krishnamoorthy
 
PPTX
DSA(1).pptx
DaniyalAli81
 
PPTX
1.3 Linked List.pptx
ssuserd2f031
 
PPTX
Data Structures and Agorithm: DS 04 Linked List.pptx
RashidFaridChishti
 
Linked lists
Eleonora Ciceri
 
dynamicList.ppt
ssuser0be977
 
singlelinkedlistasdfghzxcvbnmqwertyuiopa
rabailasghar3
 
DS_LinkedList.pptx
msohail37
 
Lec3-Linked list.pptx
FaheemMahmood2
 
Linked lists a
Khuram Shahzad
 
linked list
Ayesha Sajjad
 
linked list_MODULE 3.pptx ppt on the linked list
AnuragKumar682871
 
Link list part 1
Anaya Zafar
 
linkedlistwith animations.ppt
MuhammadShafi89
 
UNIT 2LINKEDLISdddddddddddddddddddddddddddT.pptx
shesnasuneer
 
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
linkedlist-130914084342-phpapp02.pptx
MeghaKulkarni27
 
Linked List
BHARATH KUMAR
 
Cpp lernaufgabe linked_list
Ibrahim El-Torbany
 
DS Module 03.pdf
SonaPathak5
 
Linear data structure concepts
Akila Krishnamoorthy
 
DSA(1).pptx
DaniyalAli81
 
1.3 Linked List.pptx
ssuserd2f031
 
Data Structures and Agorithm: DS 04 Linked List.pptx
RashidFaridChishti
 
Ad

More from Vivek Bhargav (10)

PPTX
Lecture 11.2 : sorting
Vivek Bhargav
 
PPTX
Lecture 11.1 : heaps
Vivek Bhargav
 
PPTX
Lecture 10 : trees - 2
Vivek Bhargav
 
PPTX
Lecture 9: Binary tree basics
Vivek Bhargav
 
PPTX
Lecture 7 & 8: Stack & queue
Vivek Bhargav
 
PPTX
Lecture 5: Asymptotic analysis of algorithms
Vivek Bhargav
 
PPTX
Lecture 4: Functions
Vivek Bhargav
 
PPTX
Lecture 3: Strings and Dynamic Memory Allocation
Vivek Bhargav
 
PPTX
Lecture 2: arrays and pointers
Vivek Bhargav
 
PPTX
Lecture 1: basic syntax
Vivek Bhargav
 
Lecture 11.2 : sorting
Vivek Bhargav
 
Lecture 11.1 : heaps
Vivek Bhargav
 
Lecture 10 : trees - 2
Vivek Bhargav
 
Lecture 9: Binary tree basics
Vivek Bhargav
 
Lecture 7 & 8: Stack & queue
Vivek Bhargav
 
Lecture 5: Asymptotic analysis of algorithms
Vivek Bhargav
 
Lecture 4: Functions
Vivek Bhargav
 
Lecture 3: Strings and Dynamic Memory Allocation
Vivek Bhargav
 
Lecture 2: arrays and pointers
Vivek Bhargav
 
Lecture 1: basic syntax
Vivek Bhargav
 

Recently uploaded (20)

PDF
this idjfk sgfdhgdhgdbhgbgrbdrwhrgbbhtgdt
WaleedAziz7
 
PDF
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
PPTX
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
PPTX
Introduction to Internal Combustion Engines - Types, Working and Camparison.pptx
UtkarshPatil98
 
PDF
William Stallings - Foundations of Modern Networking_ SDN, NFV, QoE, IoT, and...
lavanya896395
 
PPT
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
PPTX
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
PDF
Module - 5 Machine Learning-22ISE62.pdf
Dr. Shivashankar
 
PPTX
Basics of Electrical Engineering and electronics .pptx
PrabhuNarayan6
 
PPTX
Unit_I Functional Units, Instruction Sets.pptx
logaprakash9
 
PPTX
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
PDF
Bayesian Learning - Naive Bayes Algorithm
Sharmila Chidaravalli
 
PDF
NTPC PATRATU Summer internship report.pdf
hemant03701
 
PDF
Bachelor of information technology syll
SudarsanAssistantPro
 
PDF
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
PDF
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
PDF
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
PDF
A Brief Introduction About Robert Paul Hardee
Robert Paul Hardee
 
PDF
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
PPTX
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
this idjfk sgfdhgdhgdbhgbgrbdrwhrgbbhtgdt
WaleedAziz7
 
methodology-driven-mbse-murphy-july-hsv-huntsville6680038572db67488e78ff00003...
henriqueltorres1
 
Numerical-Solutions-of-Ordinary-Differential-Equations.pptx
SAMUKTHAARM
 
Introduction to Internal Combustion Engines - Types, Working and Camparison.pptx
UtkarshPatil98
 
William Stallings - Foundations of Modern Networking_ SDN, NFV, QoE, IoT, and...
lavanya896395
 
Footbinding.pptmnmkjkjkknmnnjkkkkkkkkkkkkkk
mamadoundiaye42742
 
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
Module - 5 Machine Learning-22ISE62.pdf
Dr. Shivashankar
 
Basics of Electrical Engineering and electronics .pptx
PrabhuNarayan6
 
Unit_I Functional Units, Instruction Sets.pptx
logaprakash9
 
DATA BASE MANAGEMENT AND RELATIONAL DATA
gomathisankariv2
 
Bayesian Learning - Naive Bayes Algorithm
Sharmila Chidaravalli
 
NTPC PATRATU Summer internship report.pdf
hemant03701
 
Bachelor of information technology syll
SudarsanAssistantPro
 
Data structures notes for unit 2 in computer science.pdf
sshubhamsingh265
 
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
mbse_An_Introduction_to_Arcadia_20150115.pdf
henriqueltorres1
 
A Brief Introduction About Robert Paul Hardee
Robert Paul Hardee
 
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 

Lecture 6: linked list