SlideShare a Scribd company logo
/* 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

PPTX
Stack using Linked List
PPTX
Stack using Array
PPT
StackArray stack3
PPTX
Single linked list
PPTX
Circular linked list
Stack using Linked List
Stack using Array
StackArray stack3
Single linked list
Circular linked list

What's hot (20)

DOC
Final ds record
DOCX
C program to implement linked list using array abstract data type
PDF
Recursion concepts by Divya
PPTX
C Programming Language Part 9
PPTX
Array menu
PDF
Stack concepts by Divya
PPTX
C Programming Language Part 7
PPTX
C Programming Language Part 8
DOCX
Trabajo Scilab
DOCX
Ejercicios Scilab Completo
DOCX
Taller De Scilab
PDF
Understanding storage class using nm
PDF
Introduction to Computer and Programing - Lecture 04
PPTX
C Programming Language Part 11
DOCX
Final ds record
C program to implement linked list using array abstract data type
Recursion concepts by Divya
C Programming Language Part 9
Array menu
Stack concepts by Divya
C Programming Language Part 7
C Programming Language Part 8
Trabajo Scilab
Ejercicios Scilab Completo
Taller De Scilab
Understanding storage class using nm
Introduction to Computer and Programing - Lecture 04
C Programming Language Part 11
Ad

Viewers also liked (17)

DOCX
Data Structure Project File
PDF
Programs
PPT
Algo>Stacks
DOCX
PPT
Unit7 jwfiles
PDF
07 A1 Ec01 C Programming And Data Structures
DOCX
Vatesh
PDF
Stacks,queues,linked-list
PPT
Unit ii(dsc++)
PPT
Queue and stacks
PPT
BrainFingerprintingpresentation
DOC
Ds lab manual by s.k.rath
PPT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
PPTX
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structure Project File
Programs
Algo>Stacks
Unit7 jwfiles
07 A1 Ec01 C Programming And Data Structures
Vatesh
Stacks,queues,linked-list
Unit ii(dsc++)
Queue and stacks
BrainFingerprintingpresentation
Ds lab manual by s.k.rath
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Ad

Similar to week-15x (20)

DOCX
#C programming Question 35Implement the functions required for the.docx
PDF
Datastructures asignment
DOCX
Stack prgs
PDF
VTU DSA Lab Manual
PDF
operating system ubuntu,linux,MacProgram will work only if you g.pdf
PDF
Given an expression string exp, write a java class ExpressionCheccke.pdf
PDF
VTU Data Structures Lab Manual
PDF
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
PDF
Can you give an example of a binary heap programCan you give an .pdf
PDF
DSU C&C++ Practical File Diploma
PDF
DATA STRUCTURE USING C & C++
PPTX
stack.pptx
PPTX
DS- Stack ADT
PPTX
CS8391-Data Structures Unit 2
PDF
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
DOCX
DataStructures notes
PDF
C program
PDF
Data structure circular list
PDF
#includeiostream#includestdlib.husing namespace std;class .pdf
#C programming Question 35Implement the functions required for the.docx
Datastructures asignment
Stack prgs
VTU DSA Lab Manual
operating system ubuntu,linux,MacProgram will work only if you g.pdf
Given an expression string exp, write a java class ExpressionCheccke.pdf
VTU Data Structures Lab Manual
BINARY SEARCH TREE OPERATIONS #includestdio.h#includestdlib.pdf
Can you give an example of a binary heap programCan you give an .pdf
DSU C&C++ Practical File Diploma
DATA STRUCTURE USING C & C++
stack.pptx
DS- Stack ADT
CS8391-Data Structures Unit 2
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
DataStructures notes
C program
Data structure circular list
#includeiostream#includestdlib.husing namespace std;class .pdf

More from KITE www.kitecolleges.com (20)

Recently uploaded (20)

PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Hazard Identification & Risk Assessment .pdf
PDF
Empowerment Technology for Senior High School Guide
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PPTX
Digestion and Absorption of Carbohydrates, Proteina and Fats
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PDF
What if we spent less time fighting change, and more time building what’s rig...
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
IGGE1 Understanding the Self1234567891011
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
Trump Administration's workforce development strategy
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Hazard Identification & Risk Assessment .pdf
Empowerment Technology for Senior High School Guide
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Digestion and Absorption of Carbohydrates, Proteina and Fats
Paper A Mock Exam 9_ Attempt review.pdf.
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
What if we spent less time fighting change, and more time building what’s rig...
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
History, Philosophy and sociology of education (1).pptx
IGGE1 Understanding the Self1234567891011
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Trump Administration's workforce development strategy
Chinmaya Tiranga quiz Grand Finale.pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper

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; } }