Skip to content

Instantly share code, notes, and snippets.

@boxp
Created June 2, 2014 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boxp/32d6c2bcea0a03a38549 to your computer and use it in GitHub Desktop.
Save boxp/32d6c2bcea0a03a38549 to your computer and use it in GitHub Desktop.
C言語でスタック
#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