Skip to content

Instantly share code, notes, and snippets.

@Code-Hex
Created May 15, 2015 17:16
Show Gist options
  • Save Code-Hex/f09fdaf456806ed1c9f7 to your computer and use it in GitHub Desktop.
Save Code-Hex/f09fdaf456806ed1c9f7 to your computer and use it in GitHub Desktop.
push pop の練習
#include <stdio.h>
#define N 100
int sp = 0;
int a[N];
void push(int b){
if (sp < N)
a[sp++] = b;
else
printf("Error: stack is full\n");
}
int pop(){
if (sp > 0)
return a[--sp];
else
printf("Error: stack is empty\n");
return 0;
}
int main(){
for (int i = 0; i < 50; ++i)
push(i);
for (int i = 0; i < 50; ++i)
printf("%d\n", a[i]);
printf("====================\n");
for (int i = 0; i < 50; ++i)
printf("%d\n", pop());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment