SlideShare a Scribd company logo
Programming Linked List
class LinkedList{
// declaration of the node
struct node{
int info;
node *next;
};
//private variable declared
node *start;
public:
LinkedList() //
Constructor
{
start = NULL;
}
//public fucntion declared
void AddAtBeg(int);
void AddAfter(int, int);
void Delete();
void Count();
void Search(int);
void Display();
};
20
Programming Linked List
// following function will add new element at the beginning
// also used to create first node
void LinkedList::AddAtBeg(int data)
{
node * newNode;
newNode = new node;
newNode->info = data;
newNode->next = start;
start = newNode;
}/*End of addatbeg()*/
21
Programming Linked List
//This function will add new element at any position
void LinkedList::AddAfter(int data, int pos)
{ node *newNode, *q;
q = start;
if(q == NULL) {
cout<<"nnEmpty linked list" << endl;
return;
}
//Finding the position in the linked list to insert
for(int i = 1; i < pos; i++)
q = q->next;
newNode = new node;
newNode->info = data;
newNode->next = q->next;
q->next = newNode;
}
22
Programming Linked List
void LinkedList::Delete()
{
node *tmp, *ptr;
int data;
if(start == NULL)
{
cout<<"nn List is empty"<<endl;
return;
}
cout<<"nnEnter the element for deletion : ";
cin>>data; // delete first node
if(start->info == data)
{ tmp = start;
start = start->next;
delete(tmp);
return;
}
23
ptr = start;
while(ptr->info != data) {
temp = ptr;
ptr = ptr ->next;
}
tmp->next = ptr->next;
delete(ptr); // Delete node in between, or last
node
}/*End of del()*/
24
Programming Linked List
void LinkedList::Display()
{
// Fill in the code that displays the contents of the linked list
} /*End of display() */
void LinkedList::Count()
{
// Fill in the code
that counts the
nodes of the linked
list
} /*End of count() */
void LinkedList::Search(int data)
{
// Fill in the code that will find the position of a node that
holds the ‘data’
} 25
Programming Linked List
int main()
{
int choice, n, m, position, i;
LinkedList po;
while(1)
{
cout<<"1. Add at beginningn";
cout<<"2. Add after n";
cout<<"3. Deleten";
cout<<"4. Displayn";
cout<<"5. Countn";
26
Programming Linked List
cout<<"6. Searchn"
cout<<"7. Quitn";
cout<<"n Enter your choice:";
cin>> choice;
switch(choice) {
case 1:
cout<<"nnEnter the element:";
cin>>m;
po.AddAtBeg(m);
break;
27
Programming Linked List
case 2:
cout<<"nnEnter the element:";
cin>>m;
cout<<"nPosition after inserted element:";
cin>>position;
po.AddAfter(m,position);
break;
case 3: po.Delete();
break;
case 4: po.Display();
break;
case 5: po.Count();
break;
case 6: cout<<"n
nEnter the element
to search:"; 28
Programming Linked List
cin>>m;
po.Search(m);
break;
case 7:
exit(0);
default:
c
out<<"
n
nWron
g
choice
";
}/*End of
switch */
29
Ad

Recommended

Linked list introduction and different operation
Linked list introduction and different operation
HODCSE170941
 
Algo>ADT list & linked list
Algo>ADT list & linked list
Ain-ul-Moiz Khawaja
 
Linked lists a
Linked lists a
Khuram Shahzad
 
Lecture3
Lecture3
Muhammad Zubair
 
Lecture3
Lecture3
Muhammad Zubair
 
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
hadpadrrajeshh
 
DS_LinkedList.pptx
DS_LinkedList.pptx
msohail37
 
data structures Linked List concept.pptx
data structures Linked List concept.pptx
lavanyaa88
 
dynamicList.ppt
dynamicList.ppt
ssuser0be977
 
9781285852744 ppt ch17
9781285852744 ppt ch17
Terry Yoast
 
Unit ii(dsc++)
Unit ii(dsc++)
Durga Devi
 
lecture four of data structures :Linked List-ds.ppt
lecture four of data structures :Linked List-ds.ppt
donemoremaregere376
 
Linked List.pptx
Linked List.pptx
PoonamPatil120
 
Data Structures_Linked List
Data Structures_Linked List
ThenmozhiK5
 
UNIT 2LINKEDLISdddddddddddddddddddddddddddT.pptx
UNIT 2LINKEDLISdddddddddddddddddddddddddddT.pptx
shesnasuneer
 
Bsf23006565 dsa 3rd assignment.docx............
Bsf23006565 dsa 3rd assignment.docx............
XEON14
 
Engineering.CSE.DataStructure.Linkedlist.notes
Engineering.CSE.DataStructure.Linkedlist.notes
limev72215
 
Unit 1 linked list
Unit 1 linked list
LavanyaJ28
 
singlelinkedlistasdfghzxcvbnmqwertyuiopa
singlelinkedlistasdfghzxcvbnmqwertyuiopa
rabailasghar3
 
LinkedList1LinkedList1LinkedList1111.pdf
LinkedList1LinkedList1LinkedList1111.pdf
timoemin50
 
Data structures linked list introduction.pptx
Data structures linked list introduction.pptx
Kalpana Mohan
 
DSModule2.pptx
DSModule2.pptx
ChrisSosaJacob
 
Linked Lists.pdf
Linked Lists.pdf
Kaynattariq1
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
EricvtJFraserr
 
Linked list and its operations - Traversal
Linked list and its operations - Traversal
kasthurimukila
 
Lecture 3 List of Data Structures & Algorithms
Lecture 3 List of Data Structures & Algorithms
haseebanjum2611
 
Linked list
Linked list
KalaivaniKS1
 
linkedlistwith animations.ppt
linkedlistwith animations.ppt
MuhammadShafi89
 
Link List : Introduction to List and Linked Lists
Link List : Introduction to List and Linked Lists
Anil Yadav
 
Link List REPRESENTATION OF DOUBLY LINKED LIST
Link List REPRESENTATION OF DOUBLY LINKED LIST
Anil Yadav
 

More Related Content

Similar to Link List Programming Linked List in Cpp (20)

dynamicList.ppt
dynamicList.ppt
ssuser0be977
 
9781285852744 ppt ch17
9781285852744 ppt ch17
Terry Yoast
 
Unit ii(dsc++)
Unit ii(dsc++)
Durga Devi
 
lecture four of data structures :Linked List-ds.ppt
lecture four of data structures :Linked List-ds.ppt
donemoremaregere376
 
Linked List.pptx
Linked List.pptx
PoonamPatil120
 
Data Structures_Linked List
Data Structures_Linked List
ThenmozhiK5
 
UNIT 2LINKEDLISdddddddddddddddddddddddddddT.pptx
UNIT 2LINKEDLISdddddddddddddddddddddddddddT.pptx
shesnasuneer
 
Bsf23006565 dsa 3rd assignment.docx............
Bsf23006565 dsa 3rd assignment.docx............
XEON14
 
Engineering.CSE.DataStructure.Linkedlist.notes
Engineering.CSE.DataStructure.Linkedlist.notes
limev72215
 
Unit 1 linked list
Unit 1 linked list
LavanyaJ28
 
singlelinkedlistasdfghzxcvbnmqwertyuiopa
singlelinkedlistasdfghzxcvbnmqwertyuiopa
rabailasghar3
 
LinkedList1LinkedList1LinkedList1111.pdf
LinkedList1LinkedList1LinkedList1111.pdf
timoemin50
 
Data structures linked list introduction.pptx
Data structures linked list introduction.pptx
Kalpana Mohan
 
DSModule2.pptx
DSModule2.pptx
ChrisSosaJacob
 
Linked Lists.pdf
Linked Lists.pdf
Kaynattariq1
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
EricvtJFraserr
 
Linked list and its operations - Traversal
Linked list and its operations - Traversal
kasthurimukila
 
Lecture 3 List of Data Structures & Algorithms
Lecture 3 List of Data Structures & Algorithms
haseebanjum2611
 
Linked list
Linked list
KalaivaniKS1
 
linkedlistwith animations.ppt
linkedlistwith animations.ppt
MuhammadShafi89
 
9781285852744 ppt ch17
9781285852744 ppt ch17
Terry Yoast
 
Unit ii(dsc++)
Unit ii(dsc++)
Durga Devi
 
lecture four of data structures :Linked List-ds.ppt
lecture four of data structures :Linked List-ds.ppt
donemoremaregere376
 
Data Structures_Linked List
Data Structures_Linked List
ThenmozhiK5
 
UNIT 2LINKEDLISdddddddddddddddddddddddddddT.pptx
UNIT 2LINKEDLISdddddddddddddddddddddddddddT.pptx
shesnasuneer
 
Bsf23006565 dsa 3rd assignment.docx............
Bsf23006565 dsa 3rd assignment.docx............
XEON14
 
Engineering.CSE.DataStructure.Linkedlist.notes
Engineering.CSE.DataStructure.Linkedlist.notes
limev72215
 
Unit 1 linked list
Unit 1 linked list
LavanyaJ28
 
singlelinkedlistasdfghzxcvbnmqwertyuiopa
singlelinkedlistasdfghzxcvbnmqwertyuiopa
rabailasghar3
 
LinkedList1LinkedList1LinkedList1111.pdf
LinkedList1LinkedList1LinkedList1111.pdf
timoemin50
 
Data structures linked list introduction.pptx
Data structures linked list introduction.pptx
Kalpana Mohan
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
EricvtJFraserr
 
Linked list and its operations - Traversal
Linked list and its operations - Traversal
kasthurimukila
 
Lecture 3 List of Data Structures & Algorithms
Lecture 3 List of Data Structures & Algorithms
haseebanjum2611
 
linkedlistwith animations.ppt
linkedlistwith animations.ppt
MuhammadShafi89
 

More from Anil Yadav (20)

Link List : Introduction to List and Linked Lists
Link List : Introduction to List and Linked Lists
Anil Yadav
 
Link List REPRESENTATION OF DOUBLY LINKED LIST
Link List REPRESENTATION OF DOUBLY LINKED LIST
Anil Yadav
 
ALGORITHM FOR PUSHING AN ELEMENT TO A QUEUE
ALGORITHM FOR PUSHING AN ELEMENT TO A QUEUE
Anil Yadav
 
Link List STACK and Queue USING LINKED LIST
Link List STACK and Queue USING LINKED LIST
Anil Yadav
 
Link List & ALGORITHM FOR DELETING A NODE
Link List & ALGORITHM FOR DELETING A NODE
Anil Yadav
 
Link List ALGORITHM FOR INSERTING A NODE
Link List ALGORITHM FOR INSERTING A NODE
Anil Yadav
 
Presentations Linked Lists Data Structure
Presentations Linked Lists Data Structure
Anil Yadav
 
Lec-12, 13 Quees First In First Out (FIFO)
Lec-12, 13 Quees First In First Out (FIFO)
Anil Yadav
 
Lec-12, 13 Quee s Applications of Queues
Lec-12, 13 Quee s Applications of Queues
Anil Yadav
 
Lec-12, 13 Quees Array Implementation IN
Lec-12, 13 Quees Array Implementation IN
Anil Yadav
 
Lec-12, 13 Quees In Queue IntQueue(int s)
Lec-12, 13 Quees In Queue IntQueue(int s)
Anil Yadav
 
Lec-12, 13 Quees A class for Dynamic Queue implementation
Lec-12, 13 Quees A class for Dynamic Queue implementation
Anil Yadav
 
Function enqueue inserts the value in num
Function enqueue inserts the value in num
Anil Yadav
 
Lec-12, 13 Quees -How to determine empty and full Queues?
Lec-12, 13 Quees -How to determine empty and full Queues?
Anil Yadav
 
Unit2-BIS Business Information system Data
Unit2-BIS Business Information system Data
Anil Yadav
 
Lec-12, 13 Queues - IntQueue IntQueue(int s) //constructor
Lec-12, 13 Queues - IntQueue IntQueue(int s) //constructor
Anil Yadav
 
Lec-12, 13 Quees Another implementation of Queues using Arrays
Lec-12, 13 Quees Another implementation of Queues using Arrays
Anil Yadav
 
Lec-12, 13 Quees - Circular Queues and Implementation with Array
Lec-12, 13 Quees - Circular Queues and Implementation with Array
Anil Yadav
 
Lec-32 Recursion - Divide and Conquer in Queue
Lec-32 Recursion - Divide and Conquer in Queue
Anil Yadav
 
Lec-32 Recursion -Recursion in Computer Science
Lec-32 Recursion -Recursion in Computer Science
Anil Yadav
 
Link List : Introduction to List and Linked Lists
Link List : Introduction to List and Linked Lists
Anil Yadav
 
Link List REPRESENTATION OF DOUBLY LINKED LIST
Link List REPRESENTATION OF DOUBLY LINKED LIST
Anil Yadav
 
ALGORITHM FOR PUSHING AN ELEMENT TO A QUEUE
ALGORITHM FOR PUSHING AN ELEMENT TO A QUEUE
Anil Yadav
 
Link List STACK and Queue USING LINKED LIST
Link List STACK and Queue USING LINKED LIST
Anil Yadav
 
Link List & ALGORITHM FOR DELETING A NODE
Link List & ALGORITHM FOR DELETING A NODE
Anil Yadav
 
Link List ALGORITHM FOR INSERTING A NODE
Link List ALGORITHM FOR INSERTING A NODE
Anil Yadav
 
Presentations Linked Lists Data Structure
Presentations Linked Lists Data Structure
Anil Yadav
 
Lec-12, 13 Quees First In First Out (FIFO)
Lec-12, 13 Quees First In First Out (FIFO)
Anil Yadav
 
Lec-12, 13 Quee s Applications of Queues
Lec-12, 13 Quee s Applications of Queues
Anil Yadav
 
Lec-12, 13 Quees Array Implementation IN
Lec-12, 13 Quees Array Implementation IN
Anil Yadav
 
Lec-12, 13 Quees In Queue IntQueue(int s)
Lec-12, 13 Quees In Queue IntQueue(int s)
Anil Yadav
 
Lec-12, 13 Quees A class for Dynamic Queue implementation
Lec-12, 13 Quees A class for Dynamic Queue implementation
Anil Yadav
 
Function enqueue inserts the value in num
Function enqueue inserts the value in num
Anil Yadav
 
Lec-12, 13 Quees -How to determine empty and full Queues?
Lec-12, 13 Quees -How to determine empty and full Queues?
Anil Yadav
 
Unit2-BIS Business Information system Data
Unit2-BIS Business Information system Data
Anil Yadav
 
Lec-12, 13 Queues - IntQueue IntQueue(int s) //constructor
Lec-12, 13 Queues - IntQueue IntQueue(int s) //constructor
Anil Yadav
 
Lec-12, 13 Quees Another implementation of Queues using Arrays
Lec-12, 13 Quees Another implementation of Queues using Arrays
Anil Yadav
 
Lec-12, 13 Quees - Circular Queues and Implementation with Array
Lec-12, 13 Quees - Circular Queues and Implementation with Array
Anil Yadav
 
Lec-32 Recursion - Divide and Conquer in Queue
Lec-32 Recursion - Divide and Conquer in Queue
Anil Yadav
 
Lec-32 Recursion -Recursion in Computer Science
Lec-32 Recursion -Recursion in Computer Science
Anil Yadav
 
Ad

Recently uploaded (20)

Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
RAKESH SAJJAN
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
BINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptx
Ramakrishna Reddy Bijjam
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
Revista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
Quiz Club of PSG College of Arts & Science
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
JHS SHS Back to School 2024-2025 .pptx
JHS SHS Back to School 2024-2025 .pptx
melvinapay78
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Introduction to Generative AI and Copilot.pdf
Introduction to Generative AI and Copilot.pdf
TechSoup
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
RAKESH SAJJAN
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Battle of Bookworms 2025 - U25 Literature Quiz by Pragya
Pragya - UEM Kolkata Quiz Club
 
BINARY files CSV files JSON files with example.pptx
BINARY files CSV files JSON files with example.pptx
Ramakrishna Reddy Bijjam
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
Revista digital preescolar en transformación
Revista digital preescolar en transformación
guerragallardo26
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
JHS SHS Back to School 2024-2025 .pptx
JHS SHS Back to School 2024-2025 .pptx
melvinapay78
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
SPENT QUIZ NQL JR FEST 5.0 BY SOURAV.pptx
Sourav Kr Podder
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Introduction to Generative AI and Copilot.pdf
Introduction to Generative AI and Copilot.pdf
TechSoup
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Ad

Link List Programming Linked List in Cpp

  • 1. Programming Linked List class LinkedList{ // declaration of the node struct node{ int info; node *next; }; //private variable declared node *start; public: LinkedList() // Constructor { start = NULL; } //public fucntion declared void AddAtBeg(int); void AddAfter(int, int); void Delete(); void Count(); void Search(int); void Display(); }; 20
  • 2. Programming Linked List // following function will add new element at the beginning // also used to create first node void LinkedList::AddAtBeg(int data) { node * newNode; newNode = new node; newNode->info = data; newNode->next = start; start = newNode; }/*End of addatbeg()*/ 21
  • 3. Programming Linked List //This function will add new element at any position void LinkedList::AddAfter(int data, int pos) { node *newNode, *q; q = start; if(q == NULL) { cout<<"nnEmpty linked list" << endl; return; } //Finding the position in the linked list to insert for(int i = 1; i < pos; i++) q = q->next; newNode = new node; newNode->info = data; newNode->next = q->next; q->next = newNode; } 22
  • 4. Programming Linked List void LinkedList::Delete() { node *tmp, *ptr; int data; if(start == NULL) { cout<<"nn List is empty"<<endl; return; } cout<<"nnEnter the element for deletion : "; cin>>data; // delete first node if(start->info == data) { tmp = start; start = start->next; delete(tmp); return; } 23
  • 5. ptr = start; while(ptr->info != data) { temp = ptr; ptr = ptr ->next; } tmp->next = ptr->next; delete(ptr); // Delete node in between, or last node }/*End of del()*/ 24
  • 6. Programming Linked List void LinkedList::Display() { // Fill in the code that displays the contents of the linked list } /*End of display() */ void LinkedList::Count() { // Fill in the code that counts the nodes of the linked list } /*End of count() */ void LinkedList::Search(int data) { // Fill in the code that will find the position of a node that holds the ‘data’ } 25
  • 7. Programming Linked List int main() { int choice, n, m, position, i; LinkedList po; while(1) { cout<<"1. Add at beginningn"; cout<<"2. Add after n"; cout<<"3. Deleten"; cout<<"4. Displayn"; cout<<"5. Countn"; 26
  • 8. Programming Linked List cout<<"6. Searchn" cout<<"7. Quitn"; cout<<"n Enter your choice:"; cin>> choice; switch(choice) { case 1: cout<<"nnEnter the element:"; cin>>m; po.AddAtBeg(m); break; 27
  • 9. Programming Linked List case 2: cout<<"nnEnter the element:"; cin>>m; cout<<"nPosition after inserted element:"; cin>>position; po.AddAfter(m,position); break; case 3: po.Delete(); break; case 4: po.Display(); break; case 5: po.Count(); break; case 6: cout<<"n nEnter the element to search:"; 28
  • 10. Programming Linked List cin>>m; po.Search(m); break; case 7: exit(0); default: c out<<" n nWron g choice "; }/*End of switch */ 29