#include<stdio.h>
#include<stdlib.h>
short InitHeadNode(struct Node* &, struct Node* &);
short RearInsert(struct Node* &, struct Node* &, short);
short GetListLength(struct Node* &);
short IsElemIn(struct Node* &, short);
void FindNodeIn1andIn2(struct Node* &, struct Node* &, struct Node* &, struct Node* &);
void Traversal(struct Node* &);
/* 链表结点定义 */
struct Node
{
short data;
struct Node *next;
};
int main()
{
struct Node *head1;
struct Node *rear1;
struct Node *head2;
struct Node *rear2;
struct Node *head3;
struct Node *rear3;
/* 初始化1#链表的头结点 */
if(InitHeadNode(head1, rear1) == -1)
{
/* 头结点申请失败, 程序直接结束 */
exit(0);
}
short temp;
/* 向链表中插入数据结点 */
while(1)
{
while(scanf("%hd", &temp) != 1)
{
while(getchar() != '\n') ;
printf("请输入合法数据.\n");
已知两个链表A和B分别表示两个集合, 其元素递增排列. 设计一个算法, 求出A与B的交集, 并存放在C链表中
最新推荐文章于 2024-08-15 20:11:16 发布
本文介绍了如何使用C语言实现链表的初始化、插入操作,并通过示例展示了如何求取两个链表的交集并将结果插入第三个链表。重点讨论了`InitHeadNode`、`RearInsert`和`IsElemIn`函数的实现,以及`FindNodeIn1andIn2`函数的逻辑。
摘要由CSDN通过智能技术生成