Created
May 15, 2015 17:16
-
-
Save Code-Hex/f09fdaf456806ed1c9f7 to your computer and use it in GitHub Desktop.
push pop の練習
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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