SlideShare a Scribd company logo
1 of 9
/* Write C programs that implement stack (its operations) using i) Arrays */



#include<stdio.h>

#include<conio.h>



int st_arr[20];

int t=-1;



void push_ele(int ele);

int pop_ele();

void display_ele();



void main()

{

    char choice,num1=0,num2=0;

    while(1)

    {

        clrscr();

        printf("======================================");

        printf("ntt MENU ");

        printf("n======================================");

        printf("n[1] Using Push Function");

        printf("n[2] Using Pop Function");

        printf("n[3] Elements present in Stack");
printf("n[4] Exitn");

printf("ntEnter your choice: ");

fflush(stdin);

scanf("%c",&choice);



switch(choice-'0')

{



    case 1:

    {

         printf("ntElement to be pushed: ");

         scanf("%d",&num1);

         push_ele(num1);

         break;

    }



    case 2:

    {

         num2=pop_ele(1);

         printf("ntElement to be popped: %dnt",num2);

         getch();

         break;

    }
case 3:

            {

                 display_ele();

                 getch();

                 break;

            }



            case 4:

                 exit(1);

                 break;



            default:

                 printf("nYour choice is invalid.n");

                 break;

        }

    }

}



/*Implementing the push() function. */

void push_ele(int ele)

{

    if(t==99)

    {

        printf("STACK is Full.n");
getch();

        exit(1);

    }

    st_arr[++t]=ele;

}



/*Implementing the pop() function. */

int pop_ele()

{

    int ele1;

    if(t==-1)

    {

        printf("ntSTACK is Empty.n");

        getch();

        exit(1);

    }

    return(st_arr[t--]);

}



/*Implementing display() function. */

void display_ele()

{

    int k;

    printf("ntElements present in the stack are:nt");
for(k=0;k<=t;k++)

    printf("%dt",st_arr[k]);

}



/* Write C programs that implement stack (its operations) using ii) Pointers */



#include<stdio.h>

#include<conio.h>



struct st_point

{

    int ele;

    struct st_point *l;

}



*t;

int i;



void push_ele(int j);

int pop_ele();

void display_ele();



void main()

{
char choice,num1=0,num2=0;

int i;

while(1)

{

    clrscr();

    printf("======================================");

    printf("ntt MENU ");

    printf("n======================================");

    printf("n[1] Using Push Function");

    printf("n[2] Using Pop Function");

    printf("n[3] Elements present in Stack");

    printf("n[4] Exitn");

    printf("ntEnter your choice: ");

    fflush(stdin);

    scanf("%c",&choice);



    switch(choice-'0')

    {

        case 1:

        {

             printf("ntElement to be pushed:");

             scanf("%d",&num1);

             push_ele(num1);

             break;
}



case 2:

{

     num2=pop_ele(1);

     printf("ntElement to be popped: %dnt",num2);

     getch();

     break;

}



case 3:

{

     printf("ntElements present in the stack are:nt");

     display_ele();

     getch();

     break;

}



case 4:

     exit(1);

     break;



default:

     printf("nYour choice is invalid.n");
break;

        }

    }

}



/*Inserting the elements using push function*/

void push_ele(int j)

{

    struct st_point *m;

    m=(struct st_point*)malloc(sizeof(struct st_point));

    m->ele=j;

    m->l=t;

    t=m;

    return;

}



/*Removing the elements using pop function*/

int pop_ele()

{

    if(t==NULL)

    {

        printf("nSTACK is Empty.");

        getch();

        exit(1);
}

    else

    {

        int i=t->ele;

        t=t->l;

        return (i);

    }

return 0;

}



/*Displaying the elements */

void display_ele()

{

    struct st_point *pointer=NULL;

    pointer=t;

    while(pointer!=NULL)

    {

        printf("%dt",pointer->ele);

        pointer=pointer->l;

    }

}

More Related Content

What's hot (20)

week-18x
week-18xweek-18x
week-18x
 
Final ds record
Final ds recordFinal ds record
Final ds record
 
week-10x
week-10xweek-10x
week-10x
 
week-1x
week-1xweek-1x
week-1x
 
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
 
Recursion concepts by Divya
Recursion concepts by DivyaRecursion concepts by Divya
Recursion concepts by Divya
 
Array list
Array listArray list
Array list
 
C Programming Language Part 9
C Programming Language Part 9C Programming Language Part 9
C Programming Language Part 9
 
Array menu
Array menuArray menu
Array menu
 
Avl tree
Avl treeAvl tree
Avl tree
 
Stack concepts by Divya
Stack concepts by DivyaStack concepts by Divya
Stack concepts by Divya
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
Trabajo Scilab
Trabajo ScilabTrabajo Scilab
Trabajo Scilab
 
Ejercicios Scilab Completo
Ejercicios Scilab CompletoEjercicios Scilab Completo
Ejercicios Scilab Completo
 
Taller De Scilab
Taller De ScilabTaller De Scilab
Taller De Scilab
 
Understanding storage class using nm
Understanding storage class using nmUnderstanding storage class using nm
Understanding storage class using nm
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
 
C Programming Language Part 11
C Programming Language Part 11C Programming Language Part 11
C Programming Language Part 11
 
Qprgs
QprgsQprgs
Qprgs
 

Viewers also liked (17)

Data Structure Project File
Data Structure Project FileData Structure Project File
Data Structure Project File
 
Programs
ProgramsPrograms
Programs
 
Algo>Stacks
Algo>StacksAlgo>Stacks
Algo>Stacks
 
Hargun
HargunHargun
Hargun
 
Unit7 jwfiles
Unit7 jwfilesUnit7 jwfiles
Unit7 jwfiles
 
week-20x
week-20xweek-20x
week-20x
 
07 A1 Ec01 C Programming And Data Structures
07 A1 Ec01 C Programming And Data Structures07 A1 Ec01 C Programming And Data Structures
07 A1 Ec01 C Programming And Data Structures
 
Vatesh
VateshVatesh
Vatesh
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 
Queue and stacks
Queue and stacksQueue and stacks
Queue and stacks
 
ch6
ch6ch6
ch6
 
BrainFingerprintingpresentation
BrainFingerprintingpresentationBrainFingerprintingpresentation
BrainFingerprintingpresentation
 
Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rath
 
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENTDISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
PPT (2)
PPT (2)PPT (2)
PPT (2)
 

Similar to 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.docxajoy21
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignmentsreekanth3dce
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab ManualAkhilaaReddy
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfaptcomputerzone
 
Given an expression string exp, write a java class ExpressionCheccke.pdf
Given an expression string exp, write a java class ExpressionCheccke.pdfGiven an expression string exp, write a java class ExpressionCheccke.pdf
Given an expression string exp, write a java class ExpressionCheccke.pdfinfo382133
 
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdfBINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdfARYAN20071
 
Can you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdfCan you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdfarorasales234
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++mustkeem khan
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diplomamustkeem khan
 
CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2CS8391-Data Structures Unit 2
CS8391-Data Structures Unit 2SIMONTHOMAS S
 
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfoperating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfaquazac
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular listiCreateWorld
 
#includeiostream#includestdlib.husing namespace std;class .pdf
#includeiostream#includestdlib.husing namespace std;class .pdf#includeiostream#includestdlib.husing namespace std;class .pdf
#includeiostream#includestdlib.husing namespace std;class .pdfasif1401
 

Similar to week-15x (20)

#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
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
week-17x
week-17xweek-17x
week-17x
 
Stack prgs
Stack prgsStack prgs
Stack prgs
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdf
 
Given an expression string exp, write a java class ExpressionCheccke.pdf
Given an expression string exp, write a java class ExpressionCheccke.pdfGiven an expression string exp, write a java class ExpressionCheccke.pdf
Given an expression string exp, write a java class ExpressionCheccke.pdf
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdfBINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
 
Can you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdfCan you give an example of a binary heap programCan you give an .pdf
Can you give an example of a binary heap programCan you give an .pdf
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
 
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
 
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfoperating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
C program
C programC program
C program
 
Data structure circular list
Data structure circular listData structure circular list
Data structure circular list
 
#includeiostream#includestdlib.husing namespace std;class .pdf
#includeiostream#includestdlib.husing namespace std;class .pdf#includeiostream#includestdlib.husing namespace std;class .pdf
#includeiostream#includestdlib.husing namespace std;class .pdf
 

More from KITE www.kitecolleges.com (20)

ch14
ch14ch14
ch14
 
ch16
ch16ch16
ch16
 
holographic versatile disc
holographic versatile discholographic versatile disc
holographic versatile disc
 
week-22x
week-22xweek-22x
week-22x
 
week-5x
week-5xweek-5x
week-5x
 
week-6x
week-6xweek-6x
week-6x
 
week-3x
week-3xweek-3x
week-3x
 
ch8
ch8ch8
ch8
 
Intro Expert Systems test-me.co.uk
Intro Expert Systems test-me.co.ukIntro Expert Systems test-me.co.uk
Intro Expert Systems test-me.co.uk
 
ch17
ch17ch17
ch17
 
ch4
ch4ch4
ch4
 
week-7x
week-7xweek-7x
week-7x
 
week-9x
week-9xweek-9x
week-9x
 
week-14x
week-14xweek-14x
week-14x
 
AIRBORNE
AIRBORNEAIRBORNE
AIRBORNE
 
ch2
ch2ch2
ch2
 
week-23x
week-23xweek-23x
week-23x
 
week-2x
week-2xweek-2x
week-2x
 
ch3
ch3ch3
ch3
 
Entity Classes and Attributes
Entity Classes and AttributesEntity Classes and Attributes
Entity Classes and Attributes
 

Recently uploaded

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 

Recently uploaded (20)

TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 

week-15x

  • 1. /* Write C programs that implement stack (its operations) using i) Arrays */ #include<stdio.h> #include<conio.h> int st_arr[20]; int t=-1; void push_ele(int ele); int pop_ele(); void display_ele(); void main() { char choice,num1=0,num2=0; while(1) { clrscr(); printf("======================================"); printf("ntt MENU "); printf("n======================================"); printf("n[1] Using Push Function"); printf("n[2] Using Pop Function"); printf("n[3] Elements present in Stack");
  • 2. printf("n[4] Exitn"); printf("ntEnter your choice: "); fflush(stdin); scanf("%c",&choice); switch(choice-'0') { case 1: { printf("ntElement to be pushed: "); scanf("%d",&num1); push_ele(num1); break; } case 2: { num2=pop_ele(1); printf("ntElement to be popped: %dnt",num2); getch(); break; }
  • 3. case 3: { display_ele(); getch(); break; } case 4: exit(1); break; default: printf("nYour choice is invalid.n"); break; } } } /*Implementing the push() function. */ void push_ele(int ele) { if(t==99) { printf("STACK is Full.n");
  • 4. getch(); exit(1); } st_arr[++t]=ele; } /*Implementing the pop() function. */ int pop_ele() { int ele1; if(t==-1) { printf("ntSTACK is Empty.n"); getch(); exit(1); } return(st_arr[t--]); } /*Implementing display() function. */ void display_ele() { int k; printf("ntElements present in the stack are:nt");
  • 5. for(k=0;k<=t;k++) printf("%dt",st_arr[k]); } /* Write C programs that implement stack (its operations) using ii) Pointers */ #include<stdio.h> #include<conio.h> struct st_point { int ele; struct st_point *l; } *t; int i; void push_ele(int j); int pop_ele(); void display_ele(); void main() {
  • 6. char choice,num1=0,num2=0; int i; while(1) { clrscr(); printf("======================================"); printf("ntt MENU "); printf("n======================================"); printf("n[1] Using Push Function"); printf("n[2] Using Pop Function"); printf("n[3] Elements present in Stack"); printf("n[4] Exitn"); printf("ntEnter your choice: "); fflush(stdin); scanf("%c",&choice); switch(choice-'0') { case 1: { printf("ntElement to be pushed:"); scanf("%d",&num1); push_ele(num1); break;
  • 7. } case 2: { num2=pop_ele(1); printf("ntElement to be popped: %dnt",num2); getch(); break; } case 3: { printf("ntElements present in the stack are:nt"); display_ele(); getch(); break; } case 4: exit(1); break; default: printf("nYour choice is invalid.n");
  • 8. break; } } } /*Inserting the elements using push function*/ void push_ele(int j) { struct st_point *m; m=(struct st_point*)malloc(sizeof(struct st_point)); m->ele=j; m->l=t; t=m; return; } /*Removing the elements using pop function*/ int pop_ele() { if(t==NULL) { printf("nSTACK is Empty."); getch(); exit(1);
  • 9. } else { int i=t->ele; t=t->l; return (i); } return 0; } /*Displaying the elements */ void display_ele() { struct st_point *pointer=NULL; pointer=t; while(pointer!=NULL) { printf("%dt",pointer->ele); pointer=pointer->l; } }