单链表的链接
2018-01-02 15:45
162 查看
建立长度为n的单链表A和长度为m的单链表B。编程实现将B表链接在A表的尾端,形成一个单链表A。数据类型指定为字符型。Description第一行为A表的长度n;
第二行为A表中的数据元素;
第三行为B表的长度m;
第四行为B表中的数据元素。Input输出为链接好后的A表中的所有数据元素。Output
Sample Input
第二行为A表中的数据元素;
第三行为B表的长度m;
第四行为B表中的数据元素。Input输出为链接好后的A表中的所有数据元素。Output
12345 | 4A B C D 61 2 3 4 5 6 |
1 | A B C D 1 2 3 4 5 6 |
#include <iostream> #include <malloc.h> using namespace std; typedef struct node{ char data; struct node *next; }LinkList; void createLinkList(LinkList *&l,int n){ LinkList *end,*body; l=(LinkList*)malloc(sizeof(LinkList)); end=l; char ch; for(int i=0;i<n;i++){ cin>>ch; body=(LinkList*)malloc(sizeof(LinkList)); body->data=ch; end->next=body; end=body; } end->next=NULL; } int main(){ int n,m; cin>>n; LinkList *l1; createLinkList(l1, n); cin>>m; LinkList *l2; createLinkList(l2, m); LinkList *head=l1->next; while(head->next!=NULL){ head=head->next; } head->next=l2->next; LinkList *head1=l1->next; while(head1->next!=NULL){ cout<<head1->data<<' '; head1=head1->next; } cout<<head1->data<<' '; return 0; }
相关文章推荐
- 双向循环型多链接链表
- 链接点以及链表实现
- 如何将一片内存链接成链表
- 线性表链接实现--双循环链表
- 线性表链接实现--双循环链表
- 链表的循环链接
- 给出两个表示两个非负整数的非空链表。数字以相反的顺序存储,它们的每个节点都包含一个数字。添加两个数字,并将其作为链接列表返回。
- 第四周项目3(2)链表的链接
- 线性表的链接存储结构(单链表)的实现
- 在链表里如何发现循环链接?
- 算法面试之道:在O(1)的时间内删除单链接链表的指定节点
- Linux内核部件分析 更强的链表klist 本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http://www.linuxidc.com/Linux/2011
- 第四周项目3(2)-单链表应用 链接单链表
- 3.3.4 单链表的链接
- 链表的链接(2)
- C++ 单链表基本操作分析与实现 链表 链表是一种物理存储单元上非连续、非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的。链表由一系列结点(链表中每一个元素称为结点)组成,结
- 链接点以及链表实现
- 矩阵的压缩存储(稀疏矩阵的十字链表存储、稀疏矩阵的三元组行逻辑链接的顺序表存储表示、稀疏矩阵的三元组顺序表存储表示)
- 判断两个链表是否相交和一个单链表是否有环及环的链接点(转)
- 第四周【项目三-单链表应用(2)链接】