[問題] 請問字串堆疊的問題???
請問各位強者
我想把字串寫入堆疊,然後再從堆疊中取出
請問我的程式該怎麼改!!因為一直出現錯誤
#include <stdio.h>
#include <stdlib.h>
#define MAXSTACK 100 /*定義最大堆疊容量*/
char stack[MAXSTACK]; //堆疊的陣列宣告
int top=-1; //堆疊的頂端
int isEmpty();
void push(char string);
char pop();
int main(int argc, char *argv[]) {
char string[3];
int i;
printf("請依序輸資料:\n");
fgets(string[0], 100, stdin);
push(string)
fgets(string[0], 100, stdin);
push(string);
fgets(string[0], 100, stdin);
push(string);
printf("====================\n");
while(!isEmpty()){
printf("堆疊彈出的順序為:%d\n",pop());
}
pop();
return 0;
}
/*判斷是否為空堆疊*/
int isEmpty()
{
if(top==-1)
{
return 1;
}
else
{
return 0;
}
}
/*將指定的資料存入堆疊*/
void push(string)
{
if(top>=MAXSTACK){
printf("堆疊已滿,無法再加入\n");
}
else
{
top++;
stack[top]=string;
}
}
/*從堆疊取出資料*/
char pop(){
char data;
if(isEmpty())
{
printf("堆疊已空\n");
}else
{
data=stack[top];
top--;
return data;
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.228.242.36
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1528357909.A.6AF.html
→
06/07 15:54,
7年前
, 1F
06/07 15:54, 1F
推
06/07 15:54,
7年前
, 2F
06/07 15:54, 2F
→
06/07 15:56,
7年前
, 3F
06/07 15:56, 3F
→
06/07 20:08,
7年前
, 4F
06/07 20:08, 4F
推
06/16 12:06,
7年前
, 5F
06/16 12:06, 5F