Last active
August 29, 2015 14:17
-
-
Save hiroshiro/da603aa98e8df9743006 to your computer and use it in GitHub Desktop.
古典的なスタック実装
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 <stdbool.h> | |
#include "stack.h" | |
int buf[16]; | |
int top = 0; | |
static bool isStackFull(void) { | |
return top == sizeof(buf) / sizeof(int); | |
} | |
static bool isStackEmpty(void) { | |
return top == 0; | |
} | |
//true: 成功, false: 失敗 | |
bool push(int val) { | |
if (isStackFull()) return false; | |
buf[top++] = val; | |
return true; | |
} | |
// true: 成功, false: 失敗 | |
bool pop(int *pRet) { | |
if (isStackEmpty()) return false; | |
*pRet = buf[--top]; | |
return true; | |
} |
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
#ifndef _STACK_H_ | |
#define _STACK_H_ | |
bool push(int val); | |
bool pop(int *pRat); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment