SlideShare una empresa de Scribd logo
1 de 6
Stack
-An implementation of Stack using
Single Linked List in C.
The Main Module#include<stdio.h>
#include<stdlib.h>
void push(), pop(), display();
struct stack
{
int data;
struct stack *link;
};
typedef struct stack STACK;
STACK *top=NULL;
int main()
{
int choice;
while(1)
{
printf("n----Stack Menu----n");
printf("1. Push.n");
printf("2. Pop.n");
printf("3. Display.n");
printf("4. Exit.n");
printf("Enter your choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: push();
break;
case 2: pop();
break;
case 3: display();
break;
case 4: exit(0);
break;
default: printf("Invalid option.");
}
}
}
Insert An Element Into Stack
void push()
{
STACK *temp;
int num;
temp=(STACK *)malloc(sizeof(STACK));
printf("Enter an integer value: ");
scanf("%d",&num);
temp->data=num;
temp->link=top;
top=temp;
display();
}
Delete An Element From Stack
void pop()
{
if(top==NULL)
{
printf("Stack Underflow");
}
else
{
STACK *delete_rack;
delete_rack=top;
printf("Item popped is: %dn",delete_rack->data);
top=top->link;
free(delete_rack);
display();
}
}
Display The Elements In Stack
void display()
{
if(top==NULL)
{
printf("Stack Underflow");
}
else
{
printf("The items in the stack are:");
STACK *head;
head=top;
while(head!=NULL)
{
printf("n%d",head->data);
head=head->link;
}
}
}
Presented By:-
Sayantan Sur
Thank You

Más contenido relacionado

La actualidad más candente

Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
PTCL
 

La actualidad más candente (20)

Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
 
stack & queue
stack & queuestack & queue
stack & queue
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
 
Heap sort
Heap sortHeap sort
Heap sort
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
Stack
StackStack
Stack
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
3.9 external sorting
3.9 external sorting3.9 external sorting
3.9 external sorting
 
Linked list
Linked listLinked list
Linked list
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
 
Insertion in singly linked list
Insertion in singly linked listInsertion in singly linked list
Insertion in singly linked list
 
linked lists in data structures
linked lists in data structureslinked lists in data structures
linked lists in data structures
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
 
Stack
StackStack
Stack
 
Double ended queue
Double ended queueDouble ended queue
Double ended queue
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
 
Expression trees
Expression treesExpression trees
Expression trees
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 

Destacado

Decision Support System(DSS)
Decision Support System(DSS)Decision Support System(DSS)
Decision Support System(DSS)
Sayantan Sur
 

Destacado (20)

Doubly Link List
Doubly Link ListDoubly Link List
Doubly Link List
 
Linked lists
Linked listsLinked lists
Linked lists
 
Decision Support System(DSS)
Decision Support System(DSS)Decision Support System(DSS)
Decision Support System(DSS)
 
CloudConnect 2012: The cloud application stack
CloudConnect 2012: The cloud application stackCloudConnect 2012: The cloud application stack
CloudConnect 2012: The cloud application stack
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj Meena
 
Linked stacks and queues
Linked stacks and queuesLinked stacks and queues
Linked stacks and queues
 
stack presentation
stack presentationstack presentation
stack presentation
 
Ch01
Ch01Ch01
Ch01
 
Ch02
Ch02Ch02
Ch02
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Tax DSS
Tax DSSTax DSS
Tax DSS
 
Business IT Alignment Heuristic
Business IT Alignment HeuristicBusiness IT Alignment Heuristic
Business IT Alignment Heuristic
 
Clinical decision support systems
Clinical decision support systemsClinical decision support systems
Clinical decision support systems
 
Seyedjamal Zolhavarieh - A model of knowledge quality assessment in clinical ...
Seyedjamal Zolhavarieh - A model of knowledge quality assessment in clinical ...Seyedjamal Zolhavarieh - A model of knowledge quality assessment in clinical ...
Seyedjamal Zolhavarieh - A model of knowledge quality assessment in clinical ...
 
Basic research
Basic researchBasic research
Basic research
 
Data mining applications
Data mining applicationsData mining applications
Data mining applications
 
Data Structure (Double Linked List)
Data Structure (Double Linked List)Data Structure (Double Linked List)
Data Structure (Double Linked List)
 
Organising skills
Organising skillsOrganising skills
Organising skills
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
 
Human Resource Management : The Importance of Effective Strategy and Planning
Human Resource Management : The Importance of Effective Strategy and PlanningHuman Resource Management : The Importance of Effective Strategy and Planning
Human Resource Management : The Importance of Effective Strategy and Planning
 

Similar a Stack using Linked List

Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
sreekanth3dce
 

Similar a Stack using Linked List (20)

Stack using Array
Stack using ArrayStack using Array
Stack using Array
 
Short Review of Stack
Short Review of StackShort Review of Stack
Short Review of Stack
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
week-15x
week-15xweek-15x
week-15x
 
#C programming Question 35Implement the functions required for the.docx
#C programming Question 35Implement the functions required for the.docx#C programming Question 35Implement the functions required for the.docx
#C programming Question 35Implement the functions required for the.docx
 
STACK1.docx
STACK1.docxSTACK1.docx
STACK1.docx
 
Array menu
Array menuArray menu
Array menu
 
Single linked list
Single linked listSingle linked list
Single linked list
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
 
CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2
 
DS- Stack ADT
DS- Stack ADTDS- Stack ADT
DS- Stack ADT
 
Stack of Data structure
Stack of Data structureStack of Data structure
Stack of Data structure
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
Stack prgs
Stack prgsStack prgs
Stack prgs
 
week-14x
week-14xweek-14x
week-14x
 
C program to implement linked list using array abstract data type
C program to implement linked list using array abstract data typeC program to implement linked list using array abstract data type
C program to implement linked list using array abstract data type
 
Circular queue
Circular queueCircular queue
Circular queue
 
Double linked list
Double linked listDouble linked list
Double linked list
 
Practical_File_Of_Data_Structure.pdf
Practical_File_Of_Data_Structure.pdfPractical_File_Of_Data_Structure.pdf
Practical_File_Of_Data_Structure.pdf
 

Más de Sayantan Sur (6)

Image Encryption and Compression
Image Encryption and Compression Image Encryption and Compression
Image Encryption and Compression
 
Network Security
Network SecurityNetwork Security
Network Security
 
Visual Studio IDE
Visual Studio IDEVisual Studio IDE
Visual Studio IDE
 
Ethical Hacking
Ethical HackingEthical Hacking
Ethical Hacking
 
Phising
PhisingPhising
Phising
 
International Terrorism
International Terrorism International Terrorism
International Terrorism
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Último (20)

Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 

Stack using Linked List

  • 1. Stack -An implementation of Stack using Single Linked List in C.
  • 2. The Main Module#include<stdio.h> #include<stdlib.h> void push(), pop(), display(); struct stack { int data; struct stack *link; }; typedef struct stack STACK; STACK *top=NULL; int main() { int choice; while(1) { printf("n----Stack Menu----n"); printf("1. Push.n"); printf("2. Pop.n"); printf("3. Display.n"); printf("4. Exit.n"); printf("Enter your choice: "); scanf("%d",&choice); switch(choice) { case 1: push(); break; case 2: pop(); break; case 3: display(); break; case 4: exit(0); break; default: printf("Invalid option."); } } }
  • 3. Insert An Element Into Stack void push() { STACK *temp; int num; temp=(STACK *)malloc(sizeof(STACK)); printf("Enter an integer value: "); scanf("%d",&num); temp->data=num; temp->link=top; top=temp; display(); }
  • 4. Delete An Element From Stack void pop() { if(top==NULL) { printf("Stack Underflow"); } else { STACK *delete_rack; delete_rack=top; printf("Item popped is: %dn",delete_rack->data); top=top->link; free(delete_rack); display(); } }
  • 5. Display The Elements In Stack void display() { if(top==NULL) { printf("Stack Underflow"); } else { printf("The items in the stack are:"); STACK *head; head=top; while(head!=NULL) { printf("n%d",head->data); head=head->link; } } }