10 65
865
2.1
2.1
2.1
2.1
2.1
2.1
()
Group= D R
1
2
3
A
B
A
B
Group= D R
A,B,C,···· X,Y,Z
——
1
2
3
A
B
A
B
Group= D R
A
B C
D
E F G H
——
H
B C D
E F G
A
1
2
3
A
B
A
B()
1 4
2 3
D={ 1,2,3,4}
R={(1,2),(1,3),(1,4),(2,3)
(3,4),(2,4) }
2
1
3
D={ 1,2,3 }
R={ (1,2),(2,3),(3,2),(1,3) }
——
1
2
3
A
B
A
B()
……..
……..
Lo
Lo+m
Lo+(i-1)*m
Lo+ n-1)*m
Loc(a)=Lo+ i-1)*m
……..
……..
1.
2.
3.
1
2
3
A
B
A
B()
15361400 1346
1345
h
15361400 1346
head
………………
………………
1345
15361400 1346
1345
h
1.
()
2.
3.
()
1
2
3
A
B
A
B()
for (i=1; i<=n; ++i)
for (j=1; j<= n; ++j)
c[i][j]= 0;
n) = O(n2)
2.2
n
a1a2…… ai…… an
nn=0
2.2.1
2.
1.
3.
2.2.2
1.
2.
elem length listsize
……
……
0
1
i-1V.elem[i-1]
1.,C.
#define LISTINITSIZE 100 //
typedef struct{
ElemType *elem//
int length //
int listsize //sizeofElemType
}Sqlist
C,
ElemType
ai-1…..a2a1 alegth…ai+1ai
x
Status ListInsert_sqSqlist?Vint i,ElemType x{
ifi<1 i>V.length+1return ERROR;
if(V.length>V.listsize) return OVERFLOW;
q=?V.elem[i-1];
for(p=?V.elem[V.length-1]; p>=q;p)
(p+1)=?p;
q=x;
++V.length;
return OK; }
elem length listsize
…..
a2
a1
alength
…..
ai+1
ai
0
1
i-1
i
Length-1
P
P+1
q
1.1
ai-1…..a2a1 ai ai+1 … alegth alegth… …ai+1ix
1.2
Status ListDelete_sq Sqlist?V int i,ElemType x {
if i<1 i>V.length return ERROR;
P=?V.elem[i-1];
x =?P;
q= V.elem+ V.length?1 ;
for(++p;p<=q;++p) *(p?1)=*p
V.length;
return OK;
}
2,
(,)
(ZHAOQIANSUNLIZHOUWUZHENGWANG)
:
a1 a2 ana3L …..
Typedef struct Lnode
{
Elem Type data
struct Lnode *next
} Lnode *linklist
C
2,
data next
Status ListInsert_L(LinkList &L,int i,ElemType x){
p=L; j=0;
while( p&&j<i-1)
{p=p->next; ++j;}
if( ! p j>i-1) return ERROR;
s=(struct LNode *)malloc(sizeof(struct LNode));
s->data=x; s->next=p->next; p->next=s;
return OK;
}
ba
ba
x
anai
a1 a2
P
P
ai-1
x
L
Status ListInsert_L(LinkList &L,int i,ElemType x){
p=L; j=0;
while( p&&j<i-1)
{p=p->next; ++j;}
if( ! p j>i-1) return ERROR;
s=(struct LNode *)malloc(sizeof(struct LNode));
s->data=x; s->next=p->next; p->next=s;
return OK;
}
S
anai
a1 a2
P
ai-1
L
Status ListInsert_L(LinkList &L,int i,ElemType x){
p=L; j=0;
while( p&&j<i-1)
{p=p->next; ++j;}
if( ! p j>i-1) return ERROR;
s=(struct LNode *)malloc(sizeof(struct LNode));
s->data=x; s->next=p->next; p->next=s;
return OK;
}
anai
a1 a2
ai-1
L
Status ListInsert_L(LinkList &L,int i,ElemType x){
p=L; j=0;
while( p&&j<i-1)
{p=p->next; ++j;}
if( ! p j>i-1) return ERROR;
s=(struct LNode *)malloc(sizeof(struct LNode));
s->data=x; s->next=p->next; p->next=s;
return OK;
}
P
anai
a1 a2
ai-1
L
Status ListInsert_L(LinkList &L,int i,ElemType x){
p=L; j=0;
while( p&&j<i-1)
{p=p->next; ++j;}
if( ! p j>i-1) return ERROR;
s=(struct LNode *)malloc(sizeof(struct LNode));
s->data=x; s->next=p->next; p->next=s;
return OK;
}
P
anai
a1 a2
Pa
i-1
L
Status ListInsert_L(LinkList &L,int i,ElemType x){
p=L; j=0;
while( p&&j<i-1)
{p=p->next; ++j;}
if( ! p j>i-1) return ERROR;
s=(struct LNode *)malloc(sizeof(struct LNode));
s->data=x; s->next=p->next; p->next=s;
return OK;
}
anai
a1 a2
Pa
i-1
L
Status ListInsert_L(LinkList &L,int i,ElemType x){
p=L; j=0;
while( p&&j<i-1)
{p=p->next; ++j;}
if( ! p j>i-1) return ERROR;
s=(struct LNode *)malloc(sizeof(struct LNode));
s->data=x; s->next=p->next; p->next=s;
return OK;
}
S
anai
a1 a2
Pa
i-1
x
L
Status ListInsert_L(LinkList &L,int i,ElemType x){
p=L; j=0;
while( p&&j<i-1)
{p=p->next; ++j;}
if( ! p j>i-1) return ERROR;
s=(struct LNode *)malloc(sizeof(struct LNode));
s->data=x; s->next=p->next; p->next=s;
return OK;
}
S
anai
a1 a2
Pa
i-1
x
L
Status ListInsert_L(LinkList &L,int i,ElemType x){
p=L; j=0;
while( p&&j<i-1)
{p=p->next; ++j;}
if( ! p j>i-1) return ERROR;
s=(struct LNode *)malloc(sizeof(struct LNode));
s->data=x; s->next=p->next; p->next=s;
return OK;
}
S
anai
a1 a2
P
ai-1
x
L
Status ListInsert_L(LinkList &L,int i,ElemType x){
p=L; j=0;
while( p&&j<i-1)
{p=p->next; ++j;}
if( ! p j>i-1) return ERROR;
s=(struct LNode *)malloc(sizeof(struct LNode));
s->data=x; s->next=p->next; p->next=s;
return OK;
}
,”

,”

,”

,”

,”

,”

15
,”

15
,”

15
,”

15
,”

15
,”

15
,”

15
23
,”

15
23
,”

15
23
,”

15
23
,”

15
23
,”

15
23
3
,”

15
3
23
,”

15
3
23
,”

15
3
23
,”

15
3
23
,”

15
3
23
,”

15
3
23
0
,”

15
23
0
3
,”

15
23
0
3
,”

15
23
3
ai-1a1 ai ai+1
L p q
Status ListDelete_L(LinkList &L,int i,ElemType x){
p=L; j=0;
while( p->next && j<i-1)
{ p=p->next; ++j; }
if( ! (p->next) j>i-1) return ERROR;
q=p->next ; p->next=q->next; free(q);
return OK;
}