单链表的链接 题目内容:建立长度为n的单链表A和长度为m的单链表B,n>0,m>0。编程实现将B表链接在A表的尾端,形成一个单链表A。数据类型指定为字符型。

输入格式:

第一行为A表的长度n;

第二行为A表中的数据元素;

第三行为B表的长度m;

第四行为B表中的数据元素。

输出格式:

输出为链接好后的A表中的所有数据元素。

输入样例:

4

A B C D

6

1 2 3 4 5 6

输出样例:

A B C D 1 2 3 4 5 6

#include<stdio.h>
#include<malloc.h>
struct oj {
	char a[10];
	struct oj*next;
};
struct oj*creat() {
	struct oj*head;
	struct oj*p1,*p2;
	int i=0,n;
	scanf("%d",&n);
	head=NULL;
	p1=p2=(struct oj*)malloc(sizeof(struct oj));
	scanf("%s",&p1->a);
	p1->next=NULL;
	head=p1;
	p2=p1;
	for(; i<n-1; i++) {
		p1=(struct oj*)malloc(sizeof(struct oj));
		scanf("%s",&p1->a);
		p2->next=p1;
		p2=p1;
	}
	scanf("%d",&n);
	for(i=0; i<n; i++) {
		p1=(struct oj*)malloc(sizeof(struct oj));
		scanf("%s",&p1->a);
		p2->next=p1;
		p2=p1;
	}
	p2->next=NULL;
	return head;
}

void printL(struct oj*head) {
	struct oj*p;
	p=head;
	while(p!=NULL) {
		printf("%s ",p->a);
		p=p->next;
	}
}
main() {
	struct oj*head;
	head=creat();
	printL(head);
}

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值