czyli ustatwia głowe na początwk czy coś
#include <stdio.h>
#define MAXSIZE 5
struct stack {
int stk[MAXSIZE];
int top;
};
typedef struct stack STACK;
STACK s;
void push()
{
int num;
if (s.top == (MAXSIZE - 1)) {
printf("\nStack is Full\n");
return;
}
else {
printf("\nEnter the element to be pushed\n");
scanf("%d", &num);
s.top = s.top + 1;
s.stk[s.top] = num;
}
return;
}
int IsEmpty_Full()
{
if (s.top == -1) {
printf("\nStack is Empty\n");
return 1;
}
return 0;
}
int pop()
{
int num;
if (IsEmpty_Full()) {
return (s.top);
}
else {
num = s.stk[s.top];
printf("\npoped element is = %dn", s.stk[s.top]);
s.top = s.top - 1;
}
return (num);
}
void PrintStack()
{
int i;
if (s.top == -1) {
printf("\nStack is empty\n");
return;
}
else {
printf("\n The status of the stack is \n");
for (i = s.top; i >= 0; i--) {
printf("%d\n", s.stk[i]);
}
}
printf("\n");
}
void main()
{
int choice;
int option = 1;
s.top = -1;
while (option) {
printf("\n--------- STACK ------------\n");
printf(" 1 -PUSH\t2 -POP\t3 -DISPLAY\t4 -EXIT \n");
printf("----------- ------------\n");
printf("Enter your choice\n");
scanf("%d", &choice);
switch (choice) {
case 1:
push();
break;
case 2:
pop();
break;
case 3:
PrintStack();
break;
case 4:
return;
}
// fflush(stdin); do czego to służy ?
}
return 0;
}