dt_00001 2020-10-05 17:08 采纳率: 80%
浏览 112
已采纳

[Error] ld returned 1 exit status 求问这个error怎么搞啊??真的吐了。。

链式堆栈完成中缀表达式到后缀表达式的转换
一直在gets函数报错,求问??请问代码正确了吗。。

#include <stdio.h>
#include <stdlib.h>
#include <string.h> 

#define m 100
/* run this program using the console pauser or add your own getch, system("pause") or str loop */

typedef ElementType;
typedef struct SNode *PtrToSNode;
struct SNode {
    ElementType Data;
    PtrToSNode Next;
};
typedef PtrToSNode Stack;

Stack CreateStack( ) 
{ /* 构建一个堆栈的头结点,返回该结点指针 */
    Stack S;

    S = (Stack)malloc(sizeof(struct SNode));
    S->Next = NULL;
    return S;
}

int IsEmpty ( Stack S )
{ /* 判断堆栈S是否为空,若是返回true;否则返回false */
    return ( S->Next == NULL );
}

void Push( Stack S, ElementType X )
{ /* 将元素X压入堆栈S */
    PtrToSNode TmpCell;

    TmpCell = (PtrToSNode)malloc(sizeof(struct SNode));
    TmpCell->Data = X;
    TmpCell->Next = S->Next;
    S->Next = TmpCell;

}

ElementType Pop( Stack S )  
{ /* 删除并返回堆栈S的栈顶元素 */
    PtrToSNode FirstCell;
    ElementType TopElem;

    if( IsEmpty(S) ) {
        printf("堆栈空"); 
        return  0;
    }
    else {
        FirstCell = S->Next; 
        TopElem = FirstCell->Data;
        S->Next = FirstCell->Next;
        free(FirstCell);
        return TopElem;
    }
}

void change(Stack S, ElementType str[])
{
    int i =0;
    ElementType e;
    CreatStack();
    while(str[i]!='\0')
    {
        while(isdigit(str[i]))
        {
            printf("%c",str[i++]);
            if(!isdigit(str[i]))
            {
                printf(" ");
            }
        }
        if(str[i]=='+'||str[i]=='-')
        {   
            if(S->Next=NULL)
            {
            Push(S,str[i]); 
            }   
        else
        {
            do
            {
                Pop(S);
                if(e=='(')
                {
                    Push(S, e);
                }
                else
                {
                    printf("%c",e);
                }
            }
            while(e!='(');
            {
                Push(S,str[i]);
            }
        }
    }
        else if(str[i]==')')
        {
            Pop( S);
            while(e!='(')
            {
                printf("%c",e);
                Pop(S);
            }
        }
        else if(str[i]=='*'||str[i]=='/'||str[i]=='(')
        {
            Push(S,str[i]);
        }
        else if(str[i]=='\0')
        {
            break;
        }
        else
        {
            printf("\n输入格式有误\n");
            return;
        }
        i++;
    }
    while (str[i]='\0')
    {
        Pop(S);
        printf("%c",e);
    }
}

int main(int argc, char *argv[]) {
    ElementType str[m];
    gets(str);
    Stack S;
    change(S,str);
    return 0;
}


  • 写回答

1条回答 默认 最新

  • threenewbee 2020-10-05 21:51
    关注
    加上
    #include <ctype.h>
    
    typedef ElementType;
    ->
    typedef char ElementType;
    
    CreatStack();
    ->
    CreateStack();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已采纳回答 2月13日

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改