0% found this document useful (0 votes)
32 views5 pages

Stack ADT Implementation in C

The document provides a C implementation of a Stack Abstract Data Type (ADT) using an array with basic operations such as push, pop, display, and access at the top. It includes error handling for stack overflow and underflow conditions. The main function allows user interaction to perform these operations in a loop until an exit condition is met.

Uploaded by

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

Stack ADT Implementation in C

The document provides a C implementation of a Stack Abstract Data Type (ADT) using an array with basic operations such as push, pop, display, and access at the top. It includes error handling for stack overflow and underflow conditions. The main function allows user interaction to perform these operations in a loop until an exit condition is met.

Uploaded by

Prakash S
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

IMPLEMENTATION OF STACK ADT USING ARRAY

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

#define max 5

int stk[max];

int top,topdata;

int ele;

top=-1;

//void push(int x);

//void pop();

//void display();

void push(int x)

if(top= =max-1)

Printf("STACK OVER FLOW AND INSERTION IS NOT


POSSIBLE ");

else
{

top=top+1;

stk[top]=x;

printf("Element pushed(inserted) onto the stack\t %d",x);

void pop()

if(top<0)

prinf("STACK UNDER FLOW and DELETION IS NOT


POSSIBLE");

else

printf("Element popped(Deleted) out of stack \t %d",stk[top]);

top= top-1; //logical deleting .physically we cant delete array

//element

void display()

int i;
if(top<0)

printf(" Stack empty");

else

for(i=top;i>=0;i--)

printf(“\n %d”, stk[i]);

int access_at_top()

if(top<0)

printf(“stack empty”);

return;

else

return stack[top];

void main()

int ch;
stack st;

clrscr();

do

printf("\t\tImplementation of Stack ADT-using ARRAY\n");

printf("\[Link]\t\[Link]\t\[Link] 4. access_at_top \n");

printf(“enter your choice”);

scanf(“%d”,&ch);

switch(ch)

case 1:

printf("Enter the element to be pushed");

scanf(“%d”,&ele);

push(ele);

break;

case 2:

pop();

break;

case 3:
display();

break;

case 4:

topdata=access_at_top()

printf(“data at top of stack is %d”,topdata);

}while(ch<5);

You might also like