La and LB are complementary angles, and half of LB is 30 degrees smaller than LA. How many degrees are La and LB?
Let LB be degree X
X+(X/2+30)=180
3X/2=150
X=100
So Lb is 100 degrees and La is 80 degrees
Data structure algorithm implementation: two linear tables La and LB are used to represent two sets a and B respectively. Now a new set a = A and B is required
Using two linear tables La and lb to represent two sets a and B respectively, a new set a = A and B is required
The algorithm is
void union(List &La,List Lb){
La_ len=ListLength(La);
Lb_ len=ListLength(Lb);
for(i=1;i
I wrote, you compile it, change it
Void Union (LinkList * L1, linklist * L2, linklist * & L3) / / intersection
{
LinkList *p=L1->next,*q=L2->next,*s,*c;
L3=(LinkList *)malloc(sizeof(LinkList));
L3->next=NULL;
c=L3;
while(p!=NULL&&q!=NULL)
{ if(p->datadata)
{s = (LinkList *) malloc (sizeof (LinkList)); / / copy node
s->data=p->data;
c->next=s;c=s;
p=p->next;
}
else if(p->data>q->data)
{ s=(LinkList *)malloc(sizeof(LinkList));
s->data=q->data;
c->next=s;c=s;
q=q->next;
}
else
{
s=(LinkList *)malloc(sizeof(LinkList));
s->data=p->data;
c->next=s;c=s;
p=p->next;
q=q->next;
}
}
while(q!=NULL)
{
s=(LinkList *)malloc(sizeof(LinkList));
s->data=q->data;
c->next=s;c=s;
q=q->next;
}
c->next=NULL;
while(p!=NULL)
{
s=(LinkList *)malloc(sizeof(LinkList));
s->data=p->data;
c->next=s;c=s;
p=p->next;
}
c->next=NULL;
}
Data structure (C language version) has linear table La (3,5,8110) and lb (2,6,8,9,11,15,20)?
1: If LA and LB represent two sets a and B respectively, the new set a = a ∪ B (the same element is not reserved) prediction output La = (3,5,8,11,2,6,9,15,20)
2: If LA and LB represent two sets a and B respectively, the new set a = a ∪ B (the same element is reserved) prediction output La = (2,3,5,6,8,8,9,11,11,15,20)
The data structure (C language version) is provided with linear tables La (3,5,8,11) and lb (2,6,8,9,11,15,20)
#include
#include
#define list_ init_ size 100
#define listincrement 10
typedef struct
{ int *elem;
int length;
int listsize;
} sqlist;
Int initsqlist (SqList * l) / / initialization
{
l->elem=(int *)malloc(list_ init_ size*sizeof(int));
\x09if(!l->elem)
\x09\x09exit(0);
\x09l->length=0;
\x09l->listsize=list_ init_ size;
\x09return 0;
}
int listinsert_ SQ (SqList * l, int i, int E) / / insert an element
{
\x09int *p,*q;
\x09if(il->length+1)
\x09\x09exit(0);
\x09q=&(l->elem[i-1]);
\x09for(p=&(l->elem[l->length-1]);p>=q;--p)
\x09\x09*(p+1)=*p;
\x09*q=e;
\x09++l->length;
\x09return 0;
}
Void add (SqList * l, int E) / / add to last
{
listinsert_ sq(l,l->length+1,e);
}
void disp(sqlist *l)
{
int i;
for(i=0;ilength;i++)
\x09 printf("%d ",l->elem[i]);
printf("\n");
}
Int find (SqList * l, int E) / / find whether the element exists
{
int i,t=-1;
for(i=0;ilength;i++)
\x09if(l->elem[i]==e)
\x09{t=i;break;}
return t;
}
void opt_ 1 (SqList * La, SqList * lb) / / (the same element is not reserved)
{
int i,j;
for(i=0;ilength;i++)
{
\x09j = find(la,lb->elem[i]);
if(j==-1)
\x09\x09listinsert_ sq(la,la->length+1,lb->elem[i]);
}
}
Void sort (SqList * LA) / / sort
{
\x09int i,j,k;
\x09for(i=0;ilength;i++)
\x09\x09for(j=i+1;jlength;j++)
\x09\x09{
\x09\x09 if(la->elem[i]>la->elem[j])
\x09\x09 {
\x09\x09\x09 k = la->elem[i];
\x09\x09\x09 la->elem[i] = la->elem[j];
\x09\x09\x09 la->elem[j] = k;
\x09\x09 }
\x09\x09}
}
void opt_ 2 (SqList * La, SqList * lb) / / (same element reserved)
{
int i,j;
for(i=0;ilength;i++)
{
\x09j = find(la,lb->elem[i]);
if(j!=-1)
\x09\x09listinsert_ sq(la,j+1,lb->elem[i]);
\x09else
\x09\x09listinsert_ sq(la,la->length+1,lb->elem[i]);
}
sort(la);
}
int main()
{
\x09sqlist La,Lb;
\x09initsqlist(&La);
add(&La,3);
add(&La,5);
add(&La,8);
add(&La,11);
\x09initsqlist(&Lb);
add(&Lb,2);
add(&Lb,6);
add(&Lb,8);
add(&Lb,9);
add(&Lb,11);
add(&Lb,15);
add(&Lb,20);
\x09disp(&La);
\x09disp(&Lb);
\x09opt_ 1 (& LA, & lb); / / operation (the same element is not reserved)
\x09disp(&La);
\x09 La.length =0; / / reinitialize La
add(&La,3);
add(&La,5);
add(&La,8);
add(&La,11);
\x09opt_ 2 (& LA, & lb); / / operation (same element reserved)
\x09disp(&La);
\x09
\x09return 0;
}
Output:
3 5 8 11
2 6 8 9 11 15 20
3 5 8 11 2 6 9 15 20
2 3 5 6 8 8 9 11 11 15 20