数据结构实验之链表一:顺序建立链表(SDUT 2116)
2024-09-05 06:48:50
Problem Description
输入N个整数,按照输入的顺序建立单链表存储,并遍历所建立的单链表,输出这些数据。
Input
第一行输入整数的个数N;
第二行依次输入每个整数。Output
输出这组整数。
Sample Input
8
12 56 4 6 55 15 33 62
Sample Output
12 56 4 6 55 15 33 62
Hint
不得使用数组!
#include <bits/stdc++.h>
using namespace std;
struct node
{
int data;
struct node *next;
};
int main()
{
int n;
struct node *head, *tail, *p;
head = new node;
head -> next = NULL;
tail = head;
scanf("%d",&n);
for(int i = 0; i < n; i ++)
{
p = new node;
p -> next = NULL;
scanf("%d", &p -> data);
tail -> next = p;
tail = p;
}
for(p = head -> next ; p != NULL; p = p -> next)
{
if(p == head -> next)
printf("%d",p->data);
else
printf(" %d",p->data);
}
printf("\n");
return 0;
}
最新文章
- Three.JS 从世界坐标系转换到屏幕坐标系
- [LeetCode] Longest Consecutive Sequence
- poj 2926:Requirements(最远曼哈顿距离,入门题)
- 论文笔记之:Fully-Convolutional Siamese Networks for Object Tracking
- 【WCF--初入江湖】10 序列化和传输大型数据流
- git 工具
- WLAN和WIFI的区别
- [ffmpeg 扩展第三方库编译系列] 关于须要用到cmake 创建 mingw32编译环境问题
- Java乔晓松-android中调用系统拍照功能并显示拍照的图片
- pdo 抽象层连接数据库
- thinkPHP 模板中的语法
- Luogu P1092 虫食算
- Generative Adversarial Nets[CAAE]
- 配置logback
- 去除git版本控制
- Camera2点击对焦实现
- 【learning】 扩展欧几里得算法(扩展gcd)和乘法逆元
- SQLSERVER无排序生成序号
- 一种通过MQ使缓存和数据库同步的玩法
- Redis 学习之路 (009) - Redis-cli命令最新总结