#include <stdio.h> #include <string.h> #define MAX 100 int stack[MAX]; //stackは配列を利用して実現 int top = 0; //stackは最上部(データ実際に格納する場所) int push(int x); int pop(); //配列を利移用して、スタックデータ構造を実現する // push : データの格納 int push(int x){ if(top == MAX) return -1; //満杯なら-1をエラーとして返す stack[top] = x; //データの格納 top++; //次に格納する位置へtopを移動(1つ増やす) return 1; } //pop : データ取り出し int pop(){ --top; //現在データが格納されているところにtopを移す return stack[top]; //最上部のデータを取り出して返す } int main(){ char *p_push = "push"; char *p_pop = "pop"; char input[10]; int su; for(int i=0; i<10; i++){ printf("Input operation: push/pop:"); scanf("%d", input); if(strcmp(input, p_push) == 0){ printf("Input data : "); scanf("%d", &su); push(su); }else if(strcmp(input, p_pop) == 0){ printf("poped data : %d\n",push(su)); }else{ printf("Stack is empty! "); break; } } }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/11 11:25
2017/11/11 11:28
2017/11/11 11:30
2017/11/11 11:34
2017/11/11 11:38
2017/11/11 11:41
2017/11/11 11:43
2017/11/11 11:46
2017/11/11 11:47
2017/11/11 11:50
2017/11/11 11:53
2017/11/11 11:55
2017/11/11 11:58 編集
2017/11/11 12:12
2017/11/11 12:14
2017/11/11 12:14
2017/11/11 12:17
2017/11/11 12:18
2017/11/11 12:20
2017/11/11 12:26
2017/11/11 12:29
2017/11/11 12:32
2017/11/11 12:33
2017/11/11 12:36
2017/11/11 12:43
2017/11/11 12:52
2017/11/11 12:55
2017/11/11 14:01
2017/11/11 14:10
2017/11/11 14:49
2017/11/11 14:51
2017/11/11 14:56
2017/11/11 15:01
2017/11/11 15:04
2017/11/11 15:09 編集
2017/11/11 15:08
2017/11/11 15:12
2017/11/11 15:12
2017/11/11 15:17