和乐i 2020-06-17 15:12 采纳率: 100%
浏览 99
已采纳

请大佬们看一下,我的头插法建表出了什么问题

代码如下:

#include<iostream>
#include<stdlib.h>      //malloc()函数需要用此头文件 
#include<conio.h>       //getche()函数需要用此头文件 
using namespace std; 

typedef int datatype; 
typedef struct node{    //节点类型 
    datatype data;      //数据域 
    struct node *next;  //指针域 
}linklist;

//头插法建表 
linklist *CreatListF(linklist *head){
    int ch;
    linklist *s;
    head=NULL;
    while(ch=getche()!'#'){
        s=(linklist*)malloc(sizeof(linklist));
        s->data=ch;
        s->next=head;
        head=s;
    }
    return head;
    free(s);
}

//输出函数 
void Output(linklist *head) {
    linklist *p=head;
    cout<<endl;
    cout<<"链表中的元素为:";
    while(p->next!=NULL){
        cout<<p->data;
        p=p->next;
    }
    cout<<p->data;
    cout<<endl; 
    free(p);
}

int main() 
{
    linklist *head;
    cout<<"请输入建表数据:"<<endl;
    head=CreatListF(head);
    cout<<endl;
    Output(head);

    cout<<endl;
    free(head);
}

运行后结果如下:
图片说明

  • 写回答

1条回答 默认 最新

  • qiu_shaofeng 2020-06-17 23:00
    关注

    while((ch=getche())!='#') 加个括号

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作