2620: B 链表操作

时间限制: 1 Sec  内存限制: 128 MB

提交: 418  解决: 261

题目描述

(1)编写一个函数createlink,用来建立一个动态链表(链表中的节点个数由参数count来控制)。

节点结构如下:

struct Node

{

int data;

Node * next; 

};

函数createlink的声明如下:

Node * createlink(int count);

(2)编写一个函数printlink,用来遍历输出一个链表。

函数printlink的声明如下:

void printlink(Node * head);

(3) 在主程序中调用函数createlink来动态创建链表,然后调用printlink函数遍历输出链表节点数据。



主程序如下:(提交时不用提交主程序)

int main()

{

Node * head=NULL; 

int n;

cin>>n;

head=createlink(n);

printlink(head);

return 0;

}

输入

输入要建立链表的节点个数

输入各个节点的数据

输出

输出链表中各个节点的数据

样例输入

4
1 2 3 4

样例输出

1 2 3 4

提示

提交时不用提交主程序,其他都要提交

迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……

#include<iostream>
using namespace std;
struct Node
{
int data;
Node * next;
};
Node * createlink(int count)
{
Node *p=new Node;
if(count==0)
{
p->next=NULL;
return p;
}
cin>>p->data;
p->next=createlink(count-1);
return p;
}
void printlink(Node * head)
{
if(head!=NULL)cout<<head->data;
while(head->next->next!=NULL)
{
cout<<" "<<head->next->data;
head=head->next;
}
}
int main()
{
Node * head=NULL;
int n;
cin>>n;
head=createlink(n);
printlink(head);
return 0;
}

最新文章

  1. html5标签的改变
  2. GPL与LGPL的区别
  3. ASP.NET MVC 4 Web编程
  4. SVN 的使用
  5. 机器学习&amp;&amp;数据挖掘之一:决策树基础认识
  6. STL函数模板(即算法)一览
  7. ubuntu常用文件搜索命令 分类: linux 学习笔记 ubuntu 2015-07-05 15:40 84人阅读 评论(0) 收藏
  8. UE4创建空白关卡并添加碰撞体
  9. git 客户端提交
  10. [笔记]Linux命令行大全
  11. Myeclipse 10安装与破解
  12. [APIO2015]八邻旁之桥
  13. 如何获得Android手机的软件安装列表
  14. websocket(二)--简单实现网页版群聊
  15. JavaScript原型链和继承
  16. Hero Patterns - 聚合各种 SVG 背景纹理素材的网站
  17. 猫眼电影爬取(三):requests+pyquery,并将数据存储到mysql数据库
  18. gitlab ssh clone问题解决
  19. compatible with
  20. JavaScript中七种数据类型&#183;中&#183;一

热门文章

  1. Spring MVC 入门教程示例 (一)
  2. 双栈排序 noip2008
  3. winform 如何控制输入法
  4. winform 记录全局异常捕获
  5. 安装JDK后环境变量的配置
  6. no module named staticfiles
  7. 将HTMLCollection/NodeList/伪数组转换成数组
  8. 你必须知道的ADO.NET
  9. [C++]类的继承与派生
  10. ThinkPHP 单字母函数整理