Uploaded by sagir57916

Stack

advertisement
#include <stdio.h>
void push(int, int[], int*);
int peek(int[], int*);
int pop(int[], int*);
int main() {
int stack[4];
int top = -1;
push(1, stack,
printf("%d\n",
push(2, stack,
printf("%d\n",
push(3, stack,
printf("%d\n",
push(4, stack,
printf("%d\n",
&top);
stack[top]);
&top);
stack[top]);
&top);
stack[top]);
&top);
stack[top]);
printf("Peek -> %d\n", peek(stack, &top));
pop(stack, &top);
printf("Peek -> %d\n", peek(stack, &top));
pop(stack, &top);
printf("Peek -> %d", peek(stack, &top));
return 0;
}
void push(int v, int stack[], int *top) {
(*top)++;
stack[*top] = v;
}
int peek(int stack[], int *top) {
return stack[*top];
}
int pop(int stack[], int *top) {
stack[*top] = 0;
(*top)--;
}
Download