Finance[US] Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
16.1k views
in VTU B.Tech (CSE-III Sem) Data Structure Lab by Goeduhub's Expert (7.6k points)
retagged by

Design, Develop and Implement a menu driven Program in C for the following operations on STACK of Integers (Array Implementation of Stack with maximum size MAX)

  • Push an Element on to Stack
  • Pop an Element from Stack
  • Demonstrate how Stack can be used to check Palindrome
  • Demonstrate Overflow and Underflow situations on Stack
  • Display the status of Stack
  • Exit

Support the program with appropriate functions for each of the above operations

1 Answer

0 like 1 dislike
by Goeduhub's Expert (7.6k points)
edited by
 
Best answer

Design, Develop and Implement a menu driven Program in C for the following operations on STACK of Integers 

Stack : Stack is a linear data structure that uses LIFO (last in first out)  as its functionality . here the last element is first poped out and the first element will be poped out at last . stack is a list of elements in which an element may be inserted or deleted only at one place called as top of the stack . this means that elements are removed from a stack. this means that the elements are removed from a stack in the reverse order of  that in which they were inserted into stack .example  : Plates stacked over one another in the canteen , Conversion of infix to prefix / infix to postfix

 there are two basic operations of stack : 

  1. PUSH  - Push is used to insert an element into a stack .
  2. POP - Pop is used to delete a element from a stack .

top here contains the location of top element of stack i.e the last element of stack . Maxstack gives the maximum number of element that can be held by the stack . there are two conditions of stack :

  1. If top=0 or top=null then it means that the stack is empty or we can say underflow.
  2. If top=maxstack  then stack is full or overflow condition

Program 

 #include <stdio.h>

#include <stdlib.h>

#include<conio.h>

int s[5],top=-1;

void push()

{

    if(top==4)

        printf("\nStack overflow!!!!");

    else

    {

        printf("\nEnter element to insert:");

        scanf("%d",&s[++top]);

    }

}

void pop()

{

    if(top==-1)

        printf("\nStack underflow!!!");

    else

        printf("\nElement popped is: %d",s[top--]);

}

void disp()

{

    int t=top;

    if(t==-1)

        printf("\nStack empty!!");

    else

        printf("\nStack elements are:\n");

    while(t>=0)

        printf("%d ",s[t--]);

}

void pali()

{

    int num[5],rev[5],i,t;

    for(i=0,t=top;t>=0;i++,t--)

        num[i]=rev[t]=s[t];

    for(i=0;i<=top;i++)

        if(num[i]!=rev[i])

        break;

    if(i==top+1)

        printf("\nIt is a palindrome");

    else

        printf("\nIt is not a palindrome");

}

int main()

{

    int ch;

    do

    {

        printf("\n...Stack operations.....\n");

        printf("1.PUSH\n");

        printf("2.POP\n");

        printf("3.Palindrome\n");

        printf("4.Display\n");

        printf("5.Exit\n________________\n");

        printf("Enter choice:");

        scanf("%d",&ch);

        switch(ch)

        {

            case 1:push();break;

            case 2:pop();break;

            case 3:pali();break;

            case 4:disp();break;

            case 5:exit(0);

            default:printf("\nInvalid choice");

        }

    }

    while(1);

    return 0;

}

Output

output


For more Visvesvaraya Technological University(VTU) CSE-III Sem Data Structure Lab Experiments Click Here


Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory

...