SlideShare a Scribd company logo
Deletion from Front:
if(start==NULL)
{
cout<<"No Node to delete...n";
return;
}
Start
Case 1: Linked List is Empty
13
11 12
Start
NULL
Start
Case 1: Linked List is Empty
Case 2: Linked List has Nodes
else
{
13
11 12
Start
Case 2: Linked List has Nodes
13
11 12
Start
ptr
1
2
3
ptr
13
11 12
Start
ptr
2
13
11 12
Start
ptr 3
13
12
Start
13
11 12
Start
1
ptr=start;
start=start->next;
delete ptr;
}
*******************************************************************
Program
//Linked List
#include<iostream>
using namespace std;
//Structure of a Node
struct Node
{
int info;
struct Node *next;
}*new_node,*start,*ptr;
struct Node *create_node(int);
int value;
//Create a New Node
struct Node *create_node(int value)
{ new_node = new Node();
new_node->info= value;
new_node->next=NULL;
return new_node;
}
// Insertion of Node at the begining of the Linked List
void insert_begin(struct Node *new_node)
{ //case 1: linked list is Empty
if(start==NULL)
{
start=new_node;
}
else // Linked List not empty
{
new_node->next = start;
start= new_node;
}
}
//Delete a Node from Front
void delete_begin()
{
if(start==NULL)
{
cout<<"List is emptynNo Node to deleten";
return;
}
else
{
ptr=start;
start=start->next;
delete ptr;
}
}
//Display or Traverse a Linked List
void display()
{
if(start==NULL)
{
cout<<"n No node to diaplay...nList is Empty";
return;
}
else
{
ptr = start;
while(ptr!=NULL)
{
cout<<ptr->info<<"->";
ptr=ptr->next;
}
cout<<"!!!"<<endl;
}
}
int main()
{
int flag=0;
int ch;
while(flag==0)
{
cout<<"Choose an optionn";
cout<<"1. Create a node n2. Insert at Front n3. Delete First node
n4. Display/Travarse n5. Exitn" ;
cin>>ch;
switch(ch)
{
case 1:
cout<<("Enter info for new noden");
cin>>value;
new_node = create_node(value);
if(new_node!= NULL)
{
cout<<"nnew_node created sucessfullyn";
cout<<"new_node->info = "<<new_node-
>info<<endl;
}
else
{
cout<<"Problem in creating noden Try Next
Timen";
return 0;
}
break;
case 2:
insert_begin(new_node);
cout<<"n New node inserted at the begining
successfullyn";
break;
case 3:
delete_begin();
cout<<"Node deleted sucessfully...n";
case 4:
cout<<"n Traversing Linked List..n";
display();
break;
case 5:
cout<<"Exiting...n";
return 0;
}
}
return 0;
}

More Related Content

DOC
C program to insert a node in doubly linked list
PPTX
Oct13' ----
PDF
Circular linked list
PPT
Unit ii(dsc++)
PDF
Macros in nemerle
PPT
PPTX
CSE240 Doubly Linked Lists
C program to insert a node in doubly linked list
Oct13' ----
Circular linked list
Unit ii(dsc++)
Macros in nemerle
CSE240 Doubly Linked Lists

What's hot (20)

PPTX
linked list
PPT
Data Structure Lecture 6
PPT
Circular linked list
PPTX
LINKED LISTS
PPT
Linked list
PPTX
Doubly linked list (animated)
PPTX
Linked list
PPT
header, circular and two way linked lists
PPSX
Data Structure (Double Linked List)
PDF
Doubly Link List
PPTX
Linked list
PPTX
作業系統
PPTX
Linked List - Insertion & Deletion
PPTX
Lecture 6: linked list
PPT
Mi 103 linked list
PPTX
Doubly & Circular Linked Lists
DOCX
งานย่อยที่ 7
PPSX
Data Structure (Circular Linked List)
PPTX
linked list using c
DOC
Linked List
linked list
Data Structure Lecture 6
Circular linked list
LINKED LISTS
Linked list
Doubly linked list (animated)
Linked list
header, circular and two way linked lists
Data Structure (Double Linked List)
Doubly Link List
Linked list
作業系統
Linked List - Insertion & Deletion
Lecture 6: linked list
Mi 103 linked list
Doubly & Circular Linked Lists
งานย่อยที่ 7
Data Structure (Circular Linked List)
linked list using c
Linked List
Ad

Similar to Ds006 linked list- delete from front (20)

PPTX
How to sort linked list using sorthing method.pptx
DOCX
Bsf23006565 dsa 3rd assignment.docx............
DOCX
C++ Please write the whole code that is needed for this assignment- wr.docx
PPTX
singlelinkedlistasdfghzxcvbnmqwertyuiopa
PDF
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
PDF
Linked Lists.pdf
PPTX
Data Structures and Agorithm: DS 04 Linked List.pptx
PDF
This assignment and the next (#5) involve design and development of a.pdf
PDF
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
PDF
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
PPTX
Linked lists a
PDF
File name a2.cppTaskFor this assignment, you are required to ei.pdf
PPTX
Revisiting a data structures in detail with linked list stack and queue
PDF
#includeiostream #includecstdio #includecstdlib using na.pdf
PDF
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
PPTX
data structures lists operation of lists
PDF
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
PPT
dynamicList.ppt
PPTX
Lec3-Linked list.pptx
How to sort linked list using sorthing method.pptx
Bsf23006565 dsa 3rd assignment.docx............
C++ Please write the whole code that is needed for this assignment- wr.docx
singlelinkedlistasdfghzxcvbnmqwertyuiopa
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
Linked Lists.pdf
Data Structures and Agorithm: DS 04 Linked List.pptx
This assignment and the next (#5) involve design and development of a.pdf
--INSTRUCTION- --It helps to first create if-then-else structure to fi.pdf
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdf
Linked lists a
File name a2.cppTaskFor this assignment, you are required to ei.pdf
Revisiting a data structures in detail with linked list stack and queue
#includeiostream #includecstdio #includecstdlib using na.pdf
Homework 05 - Linked Lists (C++)(1) Implement the concepts of a un.pdf
data structures lists operation of lists
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
dynamicList.ppt
Lec3-Linked list.pptx
Ad

More from jyoti_lakhani (20)

PPSX
CG02 Computer Graphic Systems.ppsx
PPTX
Projections.pptx
PPSX
CG04 Color Models.ppsx
PPSX
CG03 Random Raster Scan displays and Color CRTs.ppsx
PPTX
CG02 Computer Graphic Systems.pptx
PPSX
CG01 introduction.ppsx
PDF
Doubly linked list
PDF
Double ended queue
PDF
Tree terminology and introduction to binary tree
PDF
Priority queue
PPSX
Ds06 linked list- insert a node after a given node
PPSX
Ds06 linked list- insert a node at end
PPSX
Ds06 linked list- insert a node at beginning
PPSX
Ds06 linked list- intro and create a node
PPSX
Ds04 abstract data types (adt) jyoti lakhani
PPSX
Ds03 part i algorithms by jyoti lakhani
PPSX
Ds03 algorithms jyoti lakhani
PPSX
Ds02 flow chart and pseudo code
PPSX
Ds01 data structure introduction - by jyoti lakhani
DOCX
Ids 016 cooperative intrusion detection
CG02 Computer Graphic Systems.ppsx
Projections.pptx
CG04 Color Models.ppsx
CG03 Random Raster Scan displays and Color CRTs.ppsx
CG02 Computer Graphic Systems.pptx
CG01 introduction.ppsx
Doubly linked list
Double ended queue
Tree terminology and introduction to binary tree
Priority queue
Ds06 linked list- insert a node after a given node
Ds06 linked list- insert a node at end
Ds06 linked list- insert a node at beginning
Ds06 linked list- intro and create a node
Ds04 abstract data types (adt) jyoti lakhani
Ds03 part i algorithms by jyoti lakhani
Ds03 algorithms jyoti lakhani
Ds02 flow chart and pseudo code
Ds01 data structure introduction - by jyoti lakhani
Ids 016 cooperative intrusion detection

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Approach and Philosophy of On baking technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPT
Teaching material agriculture food technology
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
cuic standard and advanced reporting.pdf
Review of recent advances in non-invasive hemoglobin estimation
Unlocking AI with Model Context Protocol (MCP)
Digital-Transformation-Roadmap-for-Companies.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Big Data Technologies - Introduction.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Approach and Philosophy of On baking technology
Programs and apps: productivity, graphics, security and other tools
Agricultural_Statistics_at_a_Glance_2022_0.pdf
sap open course for s4hana steps from ECC to s4
Mobile App Security Testing_ A Comprehensive Guide.pdf
Teaching material agriculture food technology
NewMind AI Weekly Chronicles - August'25-Week II
The Rise and Fall of 3GPP – Time for a Sabbatical?
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation_ Review paper, used for researhc scholars
Building Integrated photovoltaic BIPV_UPV.pdf
Spectroscopy.pptx food analysis technology
Reach Out and Touch Someone: Haptics and Empathic Computing
cuic standard and advanced reporting.pdf

Ds006 linked list- delete from front

  • 1. Deletion from Front: if(start==NULL) { cout<<"No Node to delete...n"; return; } Start Case 1: Linked List is Empty 13 11 12 Start NULL Start Case 1: Linked List is Empty Case 2: Linked List has Nodes
  • 2. else { 13 11 12 Start Case 2: Linked List has Nodes 13 11 12 Start ptr 1 2 3 ptr 13 11 12 Start ptr 2 13 11 12 Start ptr 3 13 12 Start 13 11 12 Start 1
  • 3. ptr=start; start=start->next; delete ptr; } ******************************************************************* Program //Linked List #include<iostream> using namespace std; //Structure of a Node struct Node { int info; struct Node *next; }*new_node,*start,*ptr; struct Node *create_node(int); int value; //Create a New Node struct Node *create_node(int value) { new_node = new Node(); new_node->info= value; new_node->next=NULL; return new_node; } // Insertion of Node at the begining of the Linked List void insert_begin(struct Node *new_node) { //case 1: linked list is Empty if(start==NULL) { start=new_node; } else // Linked List not empty {
  • 4. new_node->next = start; start= new_node; } } //Delete a Node from Front void delete_begin() { if(start==NULL) { cout<<"List is emptynNo Node to deleten"; return; } else { ptr=start; start=start->next; delete ptr; } } //Display or Traverse a Linked List void display() { if(start==NULL) { cout<<"n No node to diaplay...nList is Empty"; return; } else { ptr = start; while(ptr!=NULL) { cout<<ptr->info<<"->"; ptr=ptr->next; } cout<<"!!!"<<endl;
  • 5. } } int main() { int flag=0; int ch; while(flag==0) { cout<<"Choose an optionn"; cout<<"1. Create a node n2. Insert at Front n3. Delete First node n4. Display/Travarse n5. Exitn" ; cin>>ch; switch(ch) { case 1: cout<<("Enter info for new noden"); cin>>value; new_node = create_node(value); if(new_node!= NULL) { cout<<"nnew_node created sucessfullyn"; cout<<"new_node->info = "<<new_node- >info<<endl; } else { cout<<"Problem in creating noden Try Next Timen"; return 0; } break; case 2: insert_begin(new_node); cout<<"n New node inserted at the begining successfullyn"; break;
  • 6. case 3: delete_begin(); cout<<"Node deleted sucessfully...n"; case 4: cout<<"n Traversing Linked List..n"; display(); break; case 5: cout<<"Exiting...n"; return 0; } } return 0; }