📄 stack1.cpp
字号:
#include "Stack1.h" /*De continuat!*/
#include<stdio.h>
void main(void)
{
int l, i;
Stack S;
initStack(S);
for(l=0;l<4;l++)
{
printf("\nIntroduceti un element:");
scanf("%d",&i);
push(S,i);
}
printf("\nVarful stivei este : %d",top(S));
}
void initStack(Stack& S)
{
int i;
S.sp=0;
for(i=0;i<100;i++)
S.vect[i]=0;
}
void push(Stack& S, Atom val)
{
if(S.sp>=100)
{
printf("EROARE! stiva plina.\n");
}
else
{
S.sp+=1;
S.vect[S.sp]=val;
}
}
Atom pop(Stack& S)
{
if(isEmpty(S))
{
printf("EROARE! stiva goala.\n");
return(0);
}
else
{
S.sp-=1;
return(S.vect[S.sp+1]);
}
}
Atom top(Stack& S)
{
if(isEmpty(S))
{
printf("EROARE! stiva goala.\n");
return(0);
}
else
return(S.vect[S.sp]);
}
int isEmpty(Stack& S)
{
return(S.sp==0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -