Data_Structure/作業/unit3/stack.c

55 lines
1.1 KiB
C
Raw Permalink Normal View History

2025-01-20 21:30:53 +08:00
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define MAX 100
int stack[MAX];
int top = -1;
int main() {
char option;
int i ;
while(1){
printf("\n*****************************\n");
printf(" <1>insert(push)\n");
printf(" <2>delete(pop)\n");
printf(" <3>list\n");
printf(" <4>quit\n");
printf("\n*****************************\n");
printf("Please enter your choice<63>G ");
option = getche();
switch(option){
case'1':
if (top >= MAX-1) /* <20><><EFBFBD><EFBFBD><EFBFBD>|<7C>w<EFBFBD><77><EFBFBD>A<EFBFBD><41><EFBFBD>ܿ<EFBFBD><DCBF>~ */
printf("Stack is full !");
else {
top++;
printf("\n\n Enter item to insert:");
scanf( "%d", &stack[top]);
}
break;
case'2':
if (top < 0) /* <20><><EFBFBD><EFBFBD><EFBFBD>|<7C>S<EFBFBD><53><EFBFBD><EFBFBD><EFBFBD>Ʀs<C6A6>b<EFBFBD>A<EFBFBD><41><EFBFBD>ܿ<EFBFBD><DCBF>~ */
printf("\n No item, stack is empty !\n");
else {
printf("\n\n Item %d deleted\n", stack[top]);
top --;
}
break;
case'3':
printf("\n<EFBFBD>ثe<EFBFBD><EFBFBD><EFBFBD>|<7C><><EFBFBD>Ʀr<C6A6><72>: ");
for(i=0;i<=top;i++){
printf("%d ",stack[i]);
}
printf("\n");
break;
case'4':
return 1;
break;
}
}
return 0;
}