操作系统
1月12日 周五
实现的功能: 栈
/* Note:Your choice is C IDE */
include “stdio.h”
define M 5
//栈
struct status
{
int a[M];
int top;
};
struct status s;
one()
{
printf(“输入入栈元素\n”);
if(s.top==M-1)
{
printf(“栈满\n”);
}
else
{
s.top++;//先加后压
scanf(“%d”,&s.a[s.top]);
printf(“入栈成功\n”);
}
}
two()
{
if(s.top==-1)
{
printf(“栈空\n”);
}
else
{
printf(“%d”,s.a[s.top]);
s.top–;//先弹后减
printf(“出栈成功\n”);
}
}
three()
{
system(“cls”);
}
void main()
{
int x;
s.top=-1;
while(1)
{
printf(“\t\t1.入栈\n”);
printf(“\t\t2.出栈\n”);
printf(“\t\t3.清屏\n”);
scanf(“%d”,&x);
switch(x)
{
case 1:one();
break;
case 2:two();
break;
case 3:three();
break;
}
}
}
最好不相见,如此便可不相恋。
最好不相知,如此便可不相思。
——仓央嘉措