SlideShare a Scribd company logo
Er. Ganesh Ram Suwal
/***** STACK IMPLEMENTATION USING SINGLY LINKED LIST *****/
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <alloc.h>
/* Global Variable */
int data;
/* Function Prototype */
void push();
void pop();
void display();
/* Structure For Node */
struct node
{
int info;
struct node *pnext;
};
struct node *pfirst,*pnew,*pthis;
void main()
{
clrscr();
int choice = 0;
printf("n********* Stack Operations using Linked List *********n");
printf("---------------------------------------------------------------------");
while(choice != 4)
{
printf("n1.Pushn2.Popn3.Shown4.Exit");
printf("nEnter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:push();
break;
case 2:pop();
break;
case 3:display();
break;
case 4:printf("Exiting....");
break;
default:printf("nSORRY !!! Please Enter valid choice ");
} // End of switch Statement
} // End of while loop
} // End main function
/* PUSH function */
void push()
{
printf("n*********************************************************n");
pnew = (struct node*)malloc(sizeof(struct node));
Er. Ganesh Ram Suwal
if(pnew == NULL)
{
printf("SORRY ! Unable to PUSH element");
}
else
{
printf("Enter data : ");
scanf("%d",&data);
pnew->info = data;
if(pfirst == NULL)
{
pnew->pnext = NULL;
pfirst = pnew;
}
else
{
pnew->pnext = pfirst;
pfirst = pnew;
}
printf("The PUSHED element = %d",pfirst->info);
}
printf("n*********************************************************n");
}
/* POP Function */
void pop()
{
printf("n*********************************************************n");
if (pfirst == NULL)
{
printf(" SORRY there is no data in STACK (STACK UNDERFLOW)");
}
else
{
data = pfirst->info;
pthis = pfirst;
pfirst = pfirst->pnext;
free(pthis);
printf("The POPED element = %d",data);
}
printf("n*********************************************************n");
}
void display()
{
int i;
printf("n*********************************************************n");
if(pfirst == NULL)
{
printf(" Stack is empty ");
}
else
{
pthis = pfirst;
Er. Ganesh Ram Suwal
printf("The element in the STACK: ");
while(pthis != NULL)
{
printf("%d ",pthis->info);
pthis = pthis->pnext;
}
}
printf("n*********************************************************n");
}
Er. Ganesh Ram Suwal
Er. Ganesh Ram Suwal

More Related Content

What's hot (20)

PDF
bpftrace - Tracing Summit 2018
AlastairRobertson9
 
PDF
Bytes in the Machine: Inside the CPython interpreter
akaptur
 
DOCX
งานย่อยที่ 7
Little Aiiry
 
PDF
Understanding the nodejs event loop
Saurabh Kumar
 
PPT
Cpp tutorial
Vikas Sharma
 
PDF
Hive practice
AnkalaRao Chinthapalli
 
PDF
Java program-to-calculate-area-and-circumference-of-circle
University of Essex
 
PDF
pg_filedump
Aleksander Alekseev
 
PDF
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
akaptur
 
PDF
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
akaptur
 
PPTX
What is recursion?
AnuragSrivastava272
 
DOCX
Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp
 
PDF
Singly Linked List
Er. Ganesh Ram Suwal
 
PDF
Sequential Async Call
Sirius Fang
 
PPT
Prgišče Lispa
Simon Belak
 
PDF
Monitoramento ambiental e alertas visuais com Zabbix - 3º Zabbix Meetup do In...
Zabbix BR
 
PDF
我在豆瓣使用Emacs
董 伟明
 
PDF
Exploring slides
akaptur
 
PDF
Metarhia KievJS 22-Feb-2018
Timur Shemsedinov
 
PDF
From Javascript To Haskell
ujihisa
 
bpftrace - Tracing Summit 2018
AlastairRobertson9
 
Bytes in the Machine: Inside the CPython interpreter
akaptur
 
งานย่อยที่ 7
Little Aiiry
 
Understanding the nodejs event loop
Saurabh Kumar
 
Cpp tutorial
Vikas Sharma
 
Hive practice
AnkalaRao Chinthapalli
 
Java program-to-calculate-area-and-circumference-of-circle
University of Essex
 
pg_filedump
Aleksander Alekseev
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
akaptur
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
akaptur
 
What is recursion?
AnuragSrivastava272
 
Jarmo van de Seijp Shadbox ERC223
Jarmo van de Seijp
 
Singly Linked List
Er. Ganesh Ram Suwal
 
Sequential Async Call
Sirius Fang
 
Prgišče Lispa
Simon Belak
 
Monitoramento ambiental e alertas visuais com Zabbix - 3º Zabbix Meetup do In...
Zabbix BR
 
我在豆瓣使用Emacs
董 伟明
 
Exploring slides
akaptur
 
Metarhia KievJS 22-Feb-2018
Timur Shemsedinov
 
From Javascript To Haskell
ujihisa
 

Similar to STACK IMPLEMENTATION USING SINGLY LINKED LIST (20)

PDF
Stack Data Structure
Er. Ganesh Ram Suwal
 
DOC
C - aptitude3
Srikanth
 
DOC
C aptitude questions
Srikanth
 
DOCX
Lab08Lab08.cppLab08Lab08.cpp.docx
DIPESH30
 
PDF
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
rohit219406
 
DOCX
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
Adamq0DJonese
 
PPT
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
Malikireddy Bramhananda Reddy
 
PDF
VTU DSA Lab Manual
AkhilaaReddy
 
PDF
DS & Algo 1 - C++ and STL Introduction
Mohammad Imam Hossain
 
PDF
PostgreSQL 9.6 새 기능 소개
PgDay.Seoul
 
PDF
Frequency .java Word frequency counter package frequ.pdf
arshiartpalace
 
PDF
Data structuresUsing java language and develop a prot.pdf
armyshoes
 
DOCX
Lab 2 Histrogram generation Author Naga Kandasamy .docx
aryan532920
 
PDF
Write a C++ program 1. Study the function process_text() in file.pdf
jillisacebi75827
 
PDF
Bubble Sort
Er. Ganesh Ram Suwal
 
DOCX
Write the definition of the linkedListKeepLast function- (Please write.docx
delicecogupdyke
 
PDF
StackInterface An interface for the ADT stack. Do not modif.pdf
ARCHANASTOREKOTA
 
DOCX
There are a number of errors in the following program- All errors are.docx
clarkjanyce
 
PDF
For each task, submit your source java code file.(1) Objective Im.pdf
dhavalbl38
 
Stack Data Structure
Er. Ganesh Ram Suwal
 
C - aptitude3
Srikanth
 
C aptitude questions
Srikanth
 
Lab08Lab08.cppLab08Lab08.cpp.docx
DIPESH30
 
C++, Implement the class BinarySearchTree, as given in listing 16-4 .pdf
rohit219406
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
Adamq0DJonese
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
Malikireddy Bramhananda Reddy
 
VTU DSA Lab Manual
AkhilaaReddy
 
DS & Algo 1 - C++ and STL Introduction
Mohammad Imam Hossain
 
PostgreSQL 9.6 새 기능 소개
PgDay.Seoul
 
Frequency .java Word frequency counter package frequ.pdf
arshiartpalace
 
Data structuresUsing java language and develop a prot.pdf
armyshoes
 
Lab 2 Histrogram generation Author Naga Kandasamy .docx
aryan532920
 
Write a C++ program 1. Study the function process_text() in file.pdf
jillisacebi75827
 
Write the definition of the linkedListKeepLast function- (Please write.docx
delicecogupdyke
 
StackInterface An interface for the ADT stack. Do not modif.pdf
ARCHANASTOREKOTA
 
There are a number of errors in the following program- All errors are.docx
clarkjanyce
 
For each task, submit your source java code file.(1) Objective Im.pdf
dhavalbl38
 
Ad

Recently uploaded (20)

PDF
Water Design_Manual_2005. KENYA FOR WASTER SUPPLY AND SEWERAGE
DancanNgutuku
 
PPTX
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
PPTX
MPMC_Module-2 xxxxxxxxxxxxxxxxxxxxx.pptx
ShivanshVaidya5
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PPTX
Hashing Introduction , hash functions and techniques
sailajam21
 
PPTX
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
PDF
Set Relation Function Practice session 24.05.2025.pdf
DrStephenStrange4
 
PPTX
Product Development & DevelopmentLecture02.pptx
zeeshanwazir2
 
PDF
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
PPTX
Thermal runway and thermal stability.pptx
godow93766
 
PPT
PPT2_Metal formingMECHANICALENGINEEIRNG .ppt
Praveen Kumar
 
PPTX
GitOps_Repo_Structure for begeinner(Scaffolindg)
DanialHabibi2
 
PPTX
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PPTX
Snet+Pro+Service+Software_SNET+Pro+2+Instructions.pptx
jenilsatikuvar1
 
PPTX
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PDF
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
Water Design_Manual_2005. KENYA FOR WASTER SUPPLY AND SEWERAGE
DancanNgutuku
 
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
MPMC_Module-2 xxxxxxxxxxxxxxxxxxxxx.pptx
ShivanshVaidya5
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
Hashing Introduction , hash functions and techniques
sailajam21
 
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
Set Relation Function Practice session 24.05.2025.pdf
DrStephenStrange4
 
Product Development & DevelopmentLecture02.pptx
zeeshanwazir2
 
Reasons for the succes of MENARD PRESSUREMETER.pdf
majdiamz
 
Thermal runway and thermal stability.pptx
godow93766
 
PPT2_Metal formingMECHANICALENGINEEIRNG .ppt
Praveen Kumar
 
GitOps_Repo_Structure for begeinner(Scaffolindg)
DanialHabibi2
 
265587293-NFPA 101 Life safety code-PPT-1.pptx
chandermwason
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
Snet+Pro+Service+Software_SNET+Pro+2+Instructions.pptx
jenilsatikuvar1
 
MobileComputingMANET2023 MobileComputingMANET2023.pptx
masterfake98765
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
MAD Unit - 2 Activity and Fragment Management in Android (Diploma IT)
JappanMavani
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
Ad

STACK IMPLEMENTATION USING SINGLY LINKED LIST

  • 1. Er. Ganesh Ram Suwal /***** STACK IMPLEMENTATION USING SINGLY LINKED LIST *****/ #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <alloc.h> /* Global Variable */ int data; /* Function Prototype */ void push(); void pop(); void display(); /* Structure For Node */ struct node { int info; struct node *pnext; }; struct node *pfirst,*pnew,*pthis; void main() { clrscr(); int choice = 0; printf("n********* Stack Operations using Linked List *********n"); printf("---------------------------------------------------------------------"); while(choice != 4) { printf("n1.Pushn2.Popn3.Shown4.Exit"); printf("nEnter your choice : "); scanf("%d",&choice); switch(choice) { case 1:push(); break; case 2:pop(); break; case 3:display(); break; case 4:printf("Exiting...."); break; default:printf("nSORRY !!! Please Enter valid choice "); } // End of switch Statement } // End of while loop } // End main function /* PUSH function */ void push() { printf("n*********************************************************n"); pnew = (struct node*)malloc(sizeof(struct node));
  • 2. Er. Ganesh Ram Suwal if(pnew == NULL) { printf("SORRY ! Unable to PUSH element"); } else { printf("Enter data : "); scanf("%d",&data); pnew->info = data; if(pfirst == NULL) { pnew->pnext = NULL; pfirst = pnew; } else { pnew->pnext = pfirst; pfirst = pnew; } printf("The PUSHED element = %d",pfirst->info); } printf("n*********************************************************n"); } /* POP Function */ void pop() { printf("n*********************************************************n"); if (pfirst == NULL) { printf(" SORRY there is no data in STACK (STACK UNDERFLOW)"); } else { data = pfirst->info; pthis = pfirst; pfirst = pfirst->pnext; free(pthis); printf("The POPED element = %d",data); } printf("n*********************************************************n"); } void display() { int i; printf("n*********************************************************n"); if(pfirst == NULL) { printf(" Stack is empty "); } else { pthis = pfirst;
  • 3. Er. Ganesh Ram Suwal printf("The element in the STACK: "); while(pthis != NULL) { printf("%d ",pthis->info); pthis = pthis->pnext; } } printf("n*********************************************************n"); }