📄 3_1.txt
字号:
#include<stdio.h>
typedef struct node{ /*结点类型*/
int data;
struct node *next;
}Llist;
intersect(Llist **c,Llist *a,Llist *b)
{
Llist *p,*q,*r,*s;
p=a,q=b;
r=*c;
while(p && q)
if(p->data==q->data){
s=(Llist *)malloc(sizeof(Llist));
s->data=p->data;
s->next=NULL;
if(*c==NULL){*c=s;
r=s;
}
else{
r->next=s;
r=s;
}
p=p->next;
q=q->next;
}
else
if(p->data<q->data)p=p->next;
else q=q->next;
}
createlist(Llist **h,int a[],int n)
{
int i;Llist *s,*r;
for(i=0;i<n;i++) /*在表尾插入结点*/
{
s=(Llist *)malloc(sizeof(Llist));
s->data=a[i];
s->next=NULL;
if(*h==NULL){*h=s;
r=s;}
else { r->next=s;
r=s;}
}
}
main()
{
int a[]={-1,3,5,7,10},b[]={-1,2,5,8,10};
Llist *a1=NULL,*b1=NULL,*c=NULL,*p;
createlist(&a1,a,5); /*建立链表A*/
createlist(&b1,b,5); /*建立链表B*/
intersect(&c,a1,b1); /*求A和B的交*/
p=c;
while(p){
printf("%d ",p->data);
p=p->next;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -