Skip to content

Instantly share code, notes, and snippets.

@koluku
Created May 15, 2017 01:17
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 koluku/71ff64d636fee7fde28df4a584b87dee to your computer and use it in GitHub Desktop.
Save koluku/71ff64d636fee7fde28df4a584b87dee to your computer and use it in GitHub Desktop.
/*--- int 型スタックを実現する構造体 ---*/
typedef struct{
int max; /* スタックの容量 */
int ptr; /* スタックポインタ */
char name[20];/* 氏名 */
int height; /* 身長 */
double vision; /* 視力 */
} PhysCheck;
/*--- スタックにデータをプッシュ ---*/
int Push(PhysCheck *s, char name, int height, double vision) {
if (s->ptr >= s->max) return -1; /* スタック満杯 */
s->name[s->ptr] = name;
s->height[s->ptr] = height;
s->vision[s->ptr] = vision;
s->ptr++;
return 0;
}
/*--- スタックからデータをポップ ---*/
int Pop(PhysCheck *s, char *name, int *height, double *vision){
if (s->ptr <= 0) return -1; /* スタックは空 */
s->ptr--;
*name = s->name[s->ptr];
*height = s->height[s->ptr];
*vision = s->vision[s->ptr];
return (0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment