0% found this document useful (0 votes)
4 views2 pages

stack using struct 1,c

This document contains a C program that implements a stack data structure using a struct. It allows users to perform operations such as push, pop, and traverse the stack. The program continuously prompts the user for input until they choose to exit.

Uploaded by

livetosing41
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

stack using struct 1,c

This document contains a C program that implements a stack data structure using a struct. It allows users to perform operations such as push, pop, and traverse the stack. The program continuously prompts the user for input until they choose to exit.

Uploaded by

livetosing41
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

stack using struct 1

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

struct stack
{
int stck;

}
struct stack s[100];
int i,j,n,top=-1;

void push()
{
if(top==n)
printf("\noverflow");
else
{
top++;
printf("\nenter element :");
scanf("%d",&s[top].stck);
}
}
void pop()
{
if(top==-1)
printf("\nunderflow");
else
{
printf("\nPopped element : %d",s[top--].stck);
}
}
void traverse()
{
printf("\n");
for(i=0;i<top;i++)
{
printf("%d\t",s[i].stck);
}
}
int main()
{
printf("enter size of stack :");
scanf("%d",&n);
while(1)
{
// system("cls");
printf("\nenter \n1->push\t2->pop\t3->display\t4->end");
scanf("%d",&j);
switch(j)
{
case 1:
{
push();break;
}
case 2:
{
pop(); getch(); break;
}
case 3:
{
traverse();getch();break;
}
case 4: exit(0);

You might also like