数据结构算法 两线性表A,B求交集。。。请高手指点!!!

[复制链接]
查看11 | 回复2 | 2017-11-24 10:54:54 | 显示全部楼层 |阅读模式
已知按值递增有序排练的两个线性表A和B,且每个线性表内部各元素互不相同。试构造线性表C,使其是A和B的交集,且其中的数字同样按值递增排列。 要求: 1)分别采用顺序表、单链表、双链表三种数据结构存储上述线性表A、B、C 2)编写一个通用的程序(无论线性表A、B和C采用顺序表、单链表还是双链表存储,该程序完全通用),实现对线性表C的构造-Known to increase the value ordered by the two linear tables A rehearsal and B, and each of the elements within the linear table from each other. Linear table test structure C, it is the intersection of A and B, and the same number of them increasing order by value. Requirements: 1) were used to order table, a single list, double-linked list data structure stored in the linear three tables A, B, C 2) write a generic program (either the linear form A, B and C using the order form, a single list, or double-linked list storage, the program is completely general), to achieve the construction of the linear form C

回复

使用道具 举报

千问 | 2017-11-24 10:54:54 | 显示全部楼层
将A与B分别排序,然后求交。例如:将A与B按升序排列,设A表头为P,B表头为Q,若A[P]>B[Q]那么Q++,若A[P][B]int A[100001],B[100001];int Ans[100001],Count,N,M;void Swap(int &a,int &b){
int Temp=a;
回复

使用道具 举报

千问 | 2017-11-24 10:54:54 | 显示全部楼层
A的元素,如果有相同的就存入LC中,然后再LB的第二个元素........
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行