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;
}

最新文章

  1. Three.JS 从世界坐标系转换到屏幕坐标系
  2. [LeetCode] Longest Consecutive Sequence
  3. poj 2926:Requirements(最远曼哈顿距离,入门题)
  4. 论文笔记之:Fully-Convolutional Siamese Networks for Object Tracking
  5. 【WCF--初入江湖】10 序列化和传输大型数据流
  6. git 工具
  7. WLAN和WIFI的区别
  8. [ffmpeg 扩展第三方库编译系列] 关于须要用到cmake 创建 mingw32编译环境问题
  9. Java乔晓松-android中调用系统拍照功能并显示拍照的图片
  10. pdo 抽象层连接数据库
  11. thinkPHP 模板中的语法
  12. Luogu P1092 虫食算
  13. Generative Adversarial Nets[CAAE]
  14. 配置logback
  15. 去除git版本控制
  16. Camera2点击对焦实现
  17. 【learning】 扩展欧几里得算法(扩展gcd)和乘法逆元
  18. SQLSERVER无排序生成序号
  19. 一种通过MQ使缓存和数据库同步的玩法
  20. Redis 学习之路 (009) - Redis-cli命令最新总结

热门文章

  1. 在javascript对象内搜索,貌似是一个新鲜的话题。
  2. Win10怎么添加开机启动项?Win10添加开机自动运行软件三种方法
  3. ASP.NET-A low-level Look at the ASP.NE
  4. C++ STL 之 list
  5. Redis和MemCache静态Map做缓存区别
  6. gradle安装教程
  7. Django_06_项目完成
  8. Pycharm中查看内置函数的源码
  9. visual studio 和visual studio code 的区别是什么?
  10. mysql基础_操作数据库以及表