卿云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日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度