1.知识点:顺序建立链表
2.题意:输入N个整数,按照输入的顺序建立单链表存储,并遍历所建立的单链表,输出这些数据
3.注意事项:尾指针移动
代码:
#include <stdio.h>
#include <stdlib.h>
typedef struct st
{
int num;
struct st *next;
}str;
int main()
{
int n, i;
str *head, *tail, *p;
head = (str *)malloc(sizeof(str));/*动态申请内存*/
head -> next = NULL;
tail = head;
scanf("%d", &n);
for(i = 0; i &l

本篇博客探讨了如何通过顺序输入的整数来建立单链表,并详细讲解了建立过程中尾指针移动的注意事项,最后展示了遍历并输出链表数据的代码实现。
最低0.47元/天 解锁文章
429





