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

Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 

Recently uploaded (20)

Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 

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