Zi_XianG0218 2021-12-24 20:04 采纳率: 100%
浏览 33
已结题

如何用倒序赋值链表,一道填空题

填空:以下程序的功能为:从键盘输入1个字符串,调用函数建立反序的链表,然后输出整个链表。补充完善程序,以实现其功能。


#include <stdio.h>

#include <malloc.h>

struct node

{  char data;

   struct node *link;

} *head;

Ins(struct node  ___________)

{

   if(head==NULL)

   {   q->link==NULL;

       head=q;

   }

   else

   {   q->link=__________;

       head=q;

   }

}

main()

{   char ch;

struct node *p;

head=NULL;

while((ch=getchar())!='\n')

{

   p=________________;

   p->data=ch;

   Ins(____________);

}

p=head;

while(p!=NULL)

{

   printf("%c",p->data);
  ________________;
   ;

}

}
  • 写回答

2条回答 默认 最新

  • _GX_ 2021-12-24 20:52
    关注
    
    #include <stdio.h>
    #include <malloc.h>
    
    struct node
    {
        char data;
        struct node *link;
    } * head;
    
    void Ins(struct node *q)
    {
        if (head == NULL)
        {
            q->link = NULL;
            head = q;
        }
        else
        {
            q->link = head;
            head = q;
        }
    }
    
    int main()
    {
        char ch;
        struct node *p;
        head = NULL;
        while ((ch = getchar()) != '\n')
        {
            p = (struct node *)malloc(sizeof(struct node));
            p->data = ch;
            Ins(p);
        }
        p = head;
        while (p != NULL)
        {
            printf("%c", p->data);
            p = p->link;
        }
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 1月1日
  • 已采纳回答 12月24日
  • 创建了问题 12月24日

悬赏问题

  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM