?? 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 + -