Created
June 2, 2014 01:23
-
-
Save boxp/32d6c2bcea0a03a38549 to your computer and use it in GitHub Desktop.
C言語でスタック
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 STACKSIZE 3000 | |
struct Stack { | |
int buffer[STACKSIZE]; | |
int length; | |
}; | |
int push(struct Stack *stack, int data) { | |
stack->buffer[stack->length] = data; | |
stack->length++; | |
return 0; | |
}; | |
int pop(struct Stack *stack) { | |
stack->length--; | |
return stack->buffer[stack->length]; | |
}; | |
int main(int argc, char const* argv[]) | |
{ | |
struct Stack marisa; | |
marisa.length = 0; | |
push(&marisa, 1); | |
push(&marisa, 1); | |
push(&marisa, 4); | |
push(&marisa, 5); | |
push(&marisa, 1); | |
push(&marisa, 4); | |
printf("%d\n",pop(&marisa)); | |
printf("%d\n",pop(&marisa)); | |
printf("%d\n",pop(&marisa)); | |
printf("%d\n",pop(&marisa)); | |
printf("%d\n",pop(&marisa)); | |
printf("%d\n",pop(&marisa)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment