[go: up one dir, main page]

0% found this document useful (0 votes)
8 views4 pages

Miss Natthida Sengmanotham 2CPR2

Uploaded by

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

Miss Natthida Sengmanotham 2CPR2

Uploaded by

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

Miss Natthida Sengmanotham 2CPR2

#include <stdio.h>

int top = -1;


int isFull()
{
if (top == 4)
return 1;
else
return 0;
}
int isEmpty()
{
if (top == -1)
return 1;
else
return 0;
}
void push(int s[5], int x)
{
if (isFull())
{
printf("\t\t\tStack is full");
}
else
{
top += 1;
s[top] = x;
printf("\t\t\tPush is successfull");
}
}
void pop(int s[5])
{
int temp;
if (isEmpty())
{
printf("\t\t\tStack is empty");
}
else
{
temp = s[top];
printf("\t\t\tThe pop element is %d", temp);
top = top - 1;
}
}

void display(int s[5])


{
int i;
if (isEmpty())
{
printf("\t\t\tStack is empty");
}
else
{
for (i = top; i > -1; i--)
{
printf("%d\t", s[i]);
}
}
}
int checkTop(int s[5])
{
if (isEmpty())
{
printf("\t\t\tStack is empty");
return -1;
}
return s[top];
}

void clearStack()
{
top = -1;
printf("\t\t\tProcess is successfull");
}

void main()
{
int choice, e, s[5];
do
{
system("cls");
printf("\t\t\t MENU \n");
printf("\t\t\t 1.push \n");
printf("\t\t\t 2.pop \n");
printf("\t\t\t 3.display\n");
printf("\t\t\t 4.Check top value \n");
printf("\t\t\t 5.Clear stack \n");
printf("\t\t\t 6.exit \n");
printf("\t\t\t Do you choose MENU : ");
scanf("%d", &choice);
if (choice == 1)
{
printf("\t\t\tPush element:");
scanf("%d", &e);
}
switch (choice)
{
case 1:
push(s, e);
break;
case 2:
pop(s);
break;
case 3:
display(s);
break;
case 4:
checkTop(s);
break;
case 5:
clearStack();

break;
}
} while (choice != 6);
}

You might also like