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日

悬赏问题

  • ¥15 基于OPENCV的人脸识别
  • ¥30 Windows Server 2016利用兩張網卡處理兩個不同網絡
  • ¥15 Python中knn问题
  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量