该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
#include
#include
#define STACK_TYPE int
#define STACK_SIZE 100
#if 1
int top_element = 0;
STACK_TYPE stack[STACK_SIZE];
void push(STACK_TYPE value);
void pop(void);
STACK_TYPE top();
STACK_TYPE EEE();
STACK_TYPE is_full();
STACK_TYPE show_stack();
void push(STACK_TYPE value)
{
assert(!is_full());
top_element += 1;
stack[top_element]=value;
}
void pop(void)
{
assert(!EEE());
printf("pop()函数调用栈顶的值=%d\n", stack[top_element]);
top_element -= 1;
}
STACK_TYPE top()
{
assert(!EEE());
return stack[top_element];
}
STACK_TYPE EEE()
{
return top_element ==0;
}
STACK_TYPE is_full()
{
return top_element ==STACK_SIZE;
}
STACK_TYPE show_stack()
{
assert(!EEE());
int n = top_element;
while (top_element>0)
{
printf("栈元素%d=%d\n", top_element,top());
stack[top_element--];
}
top_element = n;//top_element = top_element +n;
return stack[top_element];
}
int main()
{
int n,m;
int i=100;
while (1)
{
printf("1.输入栈顶元素\n");
printf("2.删除栈顶元素\n");
printf("3.显示栈顶元素\n");
printf("4.显示所有栈元素\n");
printf("5.退出程序\n");
//scanf("%d", &n);
scanf("%d", &m);
switch (m)
{
case 1:
{
scanf("%d", &n);
int*p = (int*)malloc(sizeof(int)*n);
*p = n;
push(*p);
}
break;
case 2:
pop();
getchar();
break;
case 3:
printf("栈顶元素的值=%d\n",top());
getchar();
break;
case 4:
show_stack();
getchar();
break;
case 5:
exit(0);
break;
}
getchar();
//getchar();
system("cls");
}
//push(95);
//push(102);
//pop();
//printf("pop()函数调用后栈顶的值=%d\n", top());
getchar();
return 0;
}