SlideShare a Scribd company logo
1 of 16
DATA
STRUCUTRES
AND
LINKED LIST
WHAT ARE DATA STRUCTURES?
• Data Structure is a particular way of organizing data in a
computer so that it can be used efficiently.
• Anything that can store data can be called as a Data
structure, hence Integer, Float, Boolean, Char are DS and they
are also known as Primitive Data Structures.
• We also have some complex Data Structures, which are used
to store large and connected data known as Abstract Data
Structure.
• Examples of Abstract Data Structures are: Linked List, Graph,
Tree, Stack, etc.
Classification Of Data Structures
Data Structures
Built-in
Data Structures
User Defined
Data Structures
Integer Float Character Arrays Lists Files
Linear
Lists
Non-Liner Lists
Stack QueuesLinked List GraphsTree
LINKED
LISTS
WHAT IS LINKED LIST?
• Linked List is a linear data structure. Unlike arrays, linked list elements
are not stored at contiguous location; the elements are linked using
pointers.
Data
Next
A B C D NULL
• A linked list is represented by a pointer to the first node of the linked list. The first
node is called head. If the linked list is empty, then value of head is NULL.
• Each node in a list consists of at least two parts:
1) Data
2) Pointer to the next node
Head
WHY USE LINKED LIST?
 Both Arrays and Linked List can be used to store linear data of similar types
but, The size of the arrays is fixed ,So we must know the upper limit on the
number of elements in advance.
 Inserting a new element in an array of elements is expensive.
 For example, in a system if we maintain a sorted list of IDs in an array id[].
id[] = [1000, 1010, 1050, 2000, 2040].And if we want to insert a new ID 1005, then
to maintain the sorted order, we have to move all the elements after 1000
100 101
 Linked List provide functionality of Dynamic Size(Size can be variable)
 It can grow and shrink according to data.
 Insertion of element is easily done as it uses pointer .
0 1 2 3 4
102103 104 105
5
INSERTION AND DELETION IN LINKED LIST
A B C
1.Insertion of new node at before head node.
2.Insertion of new node at specified position.
3.Deletion of node.
NULL
THE CODE
Language: C++
Functions:
▸ Create Node
▸ Insert At Begning
▸ Insert at Last
▸ Insert at position
▸ Delete
▸ Count no of nodes
▸ Display
#include<iostream.h>
#include<conio.h>
#include<process.h>
class node
{
public:
int data;
node *next;
};
class List
{
node *head;
public:
List() //constructor
{
head=NULL;
}
void create();
void display();
void insert_beg();
void insert_end();
void inserin();
void delete_node();
void count();
};
void List::create()
{
node *newn, *temp;
int n, v,i;
char ch;
cout<<"How many notes you want: ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter Data: ";
cin>>v;
newn = new node();
newn->data=v;
newn->next=NULL;
if(head==NULL)
head=newn;
else
temp->next=newn;
temp=newn;
}
}
void List::display()
{
node *temp;
temp=head;
if(temp==NULL)
cout<<"The List is empty..."<<endl;
else
{
cout<<"The Element of List is: "<<endl;
while(temp!=NULL)
{
cout<<temp->data<<" => ";
temp=temp->next;
}
cout<<endl;
}
}
void List::insert_beg()
{
node *newn;
int x;
cout<<"Enter data for new node: ";
cin>>x;
newn = new node;
newn->data=x;
newn->next=head;
head=newn;
}
void List::insert_end()
{
node *temp,*newn;
int x;
cout<<"Enter data at the end: ";
cin>>x;
newn = new node;
newn->data=x;
newn->next=NULL;
if(head==NULL)
head=newn;
for(temp=head;temp->next!=NULL;temp=temp->next);
temp->next=newn;
}
void List::insert_in()
{
node *newn,*temp;
int x,y;
newn = new node;
cout<<"Enter the data for new node: ";
cin>>x;
newn->data=x;
newn->next=NULL;
cout<<"Insert the position: ";
cin>>y;
for(temp=head;temp!=NULL && temp->data!=y;temp=temp->next);
if(temp!=NULL)
{
newn->next=temp->next;
temp->next=newn;
}
else
cout<<"Data not found...";
}
void List::count()
{
node *temp;
int cnt=0;
temp=head;
while(temp!=NULL)
{
temp=temp->next;
cnt++;
}
cout<<"Total Number of elements are: "<<cnt;
}
void main()
{
List L1;
int ch;
clrscr();
do
{
cout<<"n1. Create List"<<endl;
cout<<"2. Display List"<<endl;
cout<<"3. Insert Note At Begining"<<endl;
cout<<"4. Insert Node At End"<<endl;
cout<<"5. Insert Node In Between"<<endl;
cout<<"6. Delete Node"<<endl;
cout<<"7. Count Nodes"<<endl;
cout<<"8. Exit "<<endl;
cout<<"Enter Your Choice: ";
cin>>ch;
switch(ch)
{
case 1: L1.create();
break;
case 2: L1.display();
break;
case 3: L1.insert_beg();
break;
case 4: L1.insert_end();

More Related Content

What's hot

Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1smruti sarangi
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm KristinaBorooah
 
data structure
data structuredata structure
data structurehashim102
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structureAbrish06
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHIBCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHISowmya Jyothi
 
Introduction of data structures and algorithms
Introduction of data structures and algorithmsIntroduction of data structures and algorithms
Introduction of data structures and algorithmsVinayKumarV16
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First SearchKevin Jadiya
 
Data structure & its types
Data structure & its typesData structure & its types
Data structure & its typesRameesha Sadaqat
 
Terminology of tree
Terminology of treeTerminology of tree
Terminology of treeRacksaviR
 

What's hot (20)

Hashing
HashingHashing
Hashing
 
Data Structure and Algorithms
Data Structure and AlgorithmsData Structure and Algorithms
Data Structure and Algorithms
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1
 
Extensible hashing
Extensible hashingExtensible hashing
Extensible hashing
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
data structure
data structuredata structure
data structure
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
Linked list
Linked listLinked list
Linked list
 
Red black tree
Red black treeRed black tree
Red black tree
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHIBCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
 
Linear data structure concepts
Linear data structure conceptsLinear data structure concepts
Linear data structure concepts
 
Introduction of data structures and algorithms
Introduction of data structures and algorithmsIntroduction of data structures and algorithms
Introduction of data structures and algorithms
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Data structure & its types
Data structure & its typesData structure & its types
Data structure & its types
 
Video display devices
Video display devicesVideo display devices
Video display devices
 
Turing machine-TOC
Turing machine-TOCTuring machine-TOC
Turing machine-TOC
 
Terminology of tree
Terminology of treeTerminology of tree
Terminology of tree
 

Similar to What is Link list? explained with animations

data structures module I & II.pptx
data structures module I & II.pptxdata structures module I & II.pptx
data structures module I & II.pptxrani marri
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)Durga Devi
 
Unit 1 LINEAR DATA STRUCTURES
Unit 1  LINEAR DATA STRUCTURESUnit 1  LINEAR DATA STRUCTURES
Unit 1 LINEAR DATA STRUCTURESUsha Mahalingam
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptxSaralaT3
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptxsarala9
 
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCEARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCEVenugopalavarma Raja
 
data structure details of types and .ppt
data structure details of types and .pptdata structure details of types and .ppt
data structure details of types and .pptpoonamsngr
 
self designed Linked List
self designed Linked Listself designed Linked List
self designed Linked ListDAYASAGAR KADAM
 
2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdfSulabhPawaia
 
DATA STRUCTURES - SHORT NOTES
DATA STRUCTURES - SHORT NOTESDATA STRUCTURES - SHORT NOTES
DATA STRUCTURES - SHORT NOTESsuthi
 

Similar to What is Link list? explained with animations (20)

Data structure day1
Data structure day1Data structure day1
Data structure day1
 
data structures module I & II.pptx
data structures module I & II.pptxdata structures module I & II.pptx
data structures module I & II.pptx
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 
Unit 1 LINEAR DATA STRUCTURES
Unit 1  LINEAR DATA STRUCTURESUnit 1  LINEAR DATA STRUCTURES
Unit 1 LINEAR DATA STRUCTURES
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
 
PM.ppt
PM.pptPM.ppt
PM.ppt
 
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCEARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
 
data structure details of types and .ppt
data structure details of types and .pptdata structure details of types and .ppt
data structure details of types and .ppt
 
intr_ds.ppt
intr_ds.pptintr_ds.ppt
intr_ds.ppt
 
DSA - Copy.pptx
DSA - Copy.pptxDSA - Copy.pptx
DSA - Copy.pptx
 
self designed Linked List
self designed Linked Listself designed Linked List
self designed Linked List
 
Singly Linked List
Singly Linked ListSingly Linked List
Singly Linked List
 
Data structure
 Data structure Data structure
Data structure
 
2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf
 
lect 2-DS ALGO(online).pdf
lect 2-DS  ALGO(online).pdflect 2-DS  ALGO(online).pdf
lect 2-DS ALGO(online).pdf
 
Linked list
Linked listLinked list
Linked list
 
PM.ppt
PM.pptPM.ppt
PM.ppt
 
DS_PPT.pptx
DS_PPT.pptxDS_PPT.pptx
DS_PPT.pptx
 
DATA STRUCTURES - SHORT NOTES
DATA STRUCTURES - SHORT NOTESDATA STRUCTURES - SHORT NOTES
DATA STRUCTURES - SHORT NOTES
 

Recently uploaded

The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 

Recently uploaded (20)

The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 

What is Link list? explained with animations

  • 2. WHAT ARE DATA STRUCTURES? • Data Structure is a particular way of organizing data in a computer so that it can be used efficiently. • Anything that can store data can be called as a Data structure, hence Integer, Float, Boolean, Char are DS and they are also known as Primitive Data Structures. • We also have some complex Data Structures, which are used to store large and connected data known as Abstract Data Structure. • Examples of Abstract Data Structures are: Linked List, Graph, Tree, Stack, etc.
  • 3. Classification Of Data Structures Data Structures Built-in Data Structures User Defined Data Structures Integer Float Character Arrays Lists Files Linear Lists Non-Liner Lists Stack QueuesLinked List GraphsTree
  • 5. WHAT IS LINKED LIST? • Linked List is a linear data structure. Unlike arrays, linked list elements are not stored at contiguous location; the elements are linked using pointers. Data Next A B C D NULL • A linked list is represented by a pointer to the first node of the linked list. The first node is called head. If the linked list is empty, then value of head is NULL. • Each node in a list consists of at least two parts: 1) Data 2) Pointer to the next node Head
  • 6. WHY USE LINKED LIST?  Both Arrays and Linked List can be used to store linear data of similar types but, The size of the arrays is fixed ,So we must know the upper limit on the number of elements in advance.  Inserting a new element in an array of elements is expensive.  For example, in a system if we maintain a sorted list of IDs in an array id[]. id[] = [1000, 1010, 1050, 2000, 2040].And if we want to insert a new ID 1005, then to maintain the sorted order, we have to move all the elements after 1000 100 101  Linked List provide functionality of Dynamic Size(Size can be variable)  It can grow and shrink according to data.  Insertion of element is easily done as it uses pointer . 0 1 2 3 4 102103 104 105 5
  • 7. INSERTION AND DELETION IN LINKED LIST A B C 1.Insertion of new node at before head node. 2.Insertion of new node at specified position. 3.Deletion of node. NULL
  • 8. THE CODE Language: C++ Functions: ▸ Create Node ▸ Insert At Begning ▸ Insert at Last ▸ Insert at position ▸ Delete ▸ Count no of nodes ▸ Display
  • 9. #include<iostream.h> #include<conio.h> #include<process.h> class node { public: int data; node *next; }; class List { node *head; public: List() //constructor { head=NULL; } void create(); void display(); void insert_beg(); void insert_end(); void inserin(); void delete_node(); void count(); };
  • 10. void List::create() { node *newn, *temp; int n, v,i; char ch; cout<<"How many notes you want: "; cin>>n; for(i=0;i<n;i++) { cout<<"Enter Data: "; cin>>v; newn = new node(); newn->data=v; newn->next=NULL; if(head==NULL) head=newn; else temp->next=newn; temp=newn; } }
  • 11. void List::display() { node *temp; temp=head; if(temp==NULL) cout<<"The List is empty..."<<endl; else { cout<<"The Element of List is: "<<endl; while(temp!=NULL) { cout<<temp->data<<" => "; temp=temp->next; } cout<<endl; } }
  • 12. void List::insert_beg() { node *newn; int x; cout<<"Enter data for new node: "; cin>>x; newn = new node; newn->data=x; newn->next=head; head=newn; }
  • 13. void List::insert_end() { node *temp,*newn; int x; cout<<"Enter data at the end: "; cin>>x; newn = new node; newn->data=x; newn->next=NULL; if(head==NULL) head=newn; for(temp=head;temp->next!=NULL;temp=temp->next); temp->next=newn; }
  • 14. void List::insert_in() { node *newn,*temp; int x,y; newn = new node; cout<<"Enter the data for new node: "; cin>>x; newn->data=x; newn->next=NULL; cout<<"Insert the position: "; cin>>y; for(temp=head;temp!=NULL && temp->data!=y;temp=temp->next); if(temp!=NULL) { newn->next=temp->next; temp->next=newn; } else cout<<"Data not found..."; }
  • 15. void List::count() { node *temp; int cnt=0; temp=head; while(temp!=NULL) { temp=temp->next; cnt++; } cout<<"Total Number of elements are: "<<cnt; }
  • 16. void main() { List L1; int ch; clrscr(); do { cout<<"n1. Create List"<<endl; cout<<"2. Display List"<<endl; cout<<"3. Insert Note At Begining"<<endl; cout<<"4. Insert Node At End"<<endl; cout<<"5. Insert Node In Between"<<endl; cout<<"6. Delete Node"<<endl; cout<<"7. Count Nodes"<<endl; cout<<"8. Exit "<<endl; cout<<"Enter Your Choice: "; cin>>ch; switch(ch) { case 1: L1.create(); break; case 2: L1.display(); break; case 3: L1.insert_beg(); break; case 4: L1.insert_end();