📄 栈和队列.cpp
字号:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define MAX 100
void push(void);
void pop(void);
void print(void);
char item[MAX][20];
int top=-1;
void main()
{
char option;
while(1)
{
printf("\n**************************************\n");
printf(" 1 进栈\n");
printf(" 2 出栈\n");
printf(" 3 输出\n");
printf(" 4 退出\n");
printf("****************************************\n");
printf("请选择操作");
option=getchar();
switch(option)
{
case'1':
push();
break;
case'2':
pop();
break;
case'3':
print();
break;
case'4':
exit(0);
}
}
}
void push(void)
{
if(top>=MAX-1)
printf("\n\nStack is full!\n");
else
{
getchar();
top++;
printf("\n\nPlease enter item to insert:");
gets(item[top]);
}
}
void pop(void)
{
if(top<0)
printf("\n\nNo item,stack is empty!\n");
else
{
printf("\n\n Item %s deleted\n",item[top]);
top--;
}
}
void print(void)
{
int count=0;
if(top<0)
printf("\n\n No item,stack is empty\n");
else
{
printf("\n\n ITEM\n");
printf("----------------\n");
for(int i=0;i<=top;i++)
{
printf(" %20s\n",item[i]);
count++;
if(count%20==0)getchar();
}
printf("---------------------");
printf("\n Total item:%d\n",count);
getchar();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -