卿云861 2022-04-29 17:35 采纳率: 97.8%
浏览 35
已结题

这个代码是我在网上搜的,但看不明白,能给我在代码后面标上注释吗?

编写一个程序,读入一行字符,且每个字符存入一个结点,按输入顺序建立一个链表的结点序列,然后再按相反顺序输出并释放全部结点。
函数接口定义:
在这里描述函数接口。例如:
struct Node *create();
void print(struct Node *head);
函数create,要求从表尾开始逆向建立链表;函数print,要求相反顺序输出并释放全部结点。
裁判测试程序样例:
#include <stdio.h>
#include <malloc.h>
struct Node
{
char info;
struct Node *link;
};

struct Node *create();
void print(struct Node *head);

int main()
{
struct Node *head;
head=create();
print(head);
return 0;
}

/* 你的代码将被嵌在这里 */
输入样例:
abcd
输出样例:
dcba
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
C (gcc)

struct Node *create()
{
struct Node *top,*p,*head;
char s;
top=NULL;
while((s=getchar())!='\n')
{
p=(struct Node *)malloc(sizeof(struct Node));
p->info=s;
p->link=top;
top=p;
}
return (top);
}
void print(struct Node *head)
{
struct Node *p;
p=head;
while(head!=NULL)
{
p=head;
head=p->link;
printf("%c",p->info);
free;
}
}

  • 写回答

1条回答 默认 最新

  • 吕布辕门 后端领域新星创作者 2022-04-29 17:51
    关注

    如有帮助,请采纳

    img

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

报告相同问题?

问题事件

  • 系统已结题 5月9日
  • 已采纳回答 5月1日
  • 创建了问题 4月29日

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题