10 65
865
9761059 95 97.6
2.2
n
a1a2…… ai…… an
nn=0
2.2.1
2.
1.
3.
2.2.2
1.
2.
1.
……..
……..
b
b+m
b+(i-1)*m
b+(maxlen-1)*m
Loc(i)=b +i-1)*m
()
……
……
0
1
i
——C.
#define M 100 /*M100M*/
int V[M]; /*V*/
iai
Loc(ai)=Loc(a1)+(i-1)*m
V[]
V[ ]
…..
a2
a1
an
…..
ai+1
ai
0
1
i-1
i
n-1
1- 1
ai-1…..a2a1 alength
…
ai+1ai
x
ai-1…..a2a1 ai ai+1 … alength alength… …ai+1ix
int insq(int iint x,int V[ ],int M,int *p/ **/
{ /*Vi xi 1? i? n */
int nj
n=*p; / **/
ifn==M) / *Mp */
{ printf("overflow \n"); return (0);}
if((i<1) (i>n+1))
{printf("i is error \n");return (0);} /*i */
else { for (j=n; j>=i; j- -) V[j]=V[j-1]; /**/
V[j]=x; /* x */
p=++n; /* 1,p */
return (1);
}
}
viod main( )
{ int M=10;n=4; /*M,n,*/
int result,k;
static int V[10]={3,5,7,10}; /* */
result=insq(2,4,V,10,&n); /*,24*/
if ( result==1) { printf ("success ! \n");
for (k=0; k<n; k++) printf ("%d",V[k]);}
else printf("failure!");
}
:
success! 3 4 5 7 10
1- 2
int delsq(int i,int V[ ],int *p
{ /*Vi */
int n,j;
n=*p;
ifi<1 i>n
{ printf("This element is not in the list \n"); return (0);}
else { for (j=i;j<n;j++) V[j-1]=V[j];/**/
*p=--n; /*1*/
return (1);
}
}
2,
ZHAOQIANSUNLIZHOUWUZHENGWANG
:
a1 a2 ana3L …..
C
2,
data next
typedef struct LNode
{
int data;
Struct LNode *next;
} JD;
ba
ba
x
P
P
S
P
ba
ba
x
anai
a1 a2
P
P
ai-1
x
L
S
anai
a1 a2
P a
i-1
L
void lbcr (JD *p,int x)
{ / * P */
JD *s; /* */
s=(JD *)malloc(sizeof(JD )); /* */
s->data=x;
s->next=p->next;
p->next=s;
return OK;
}
anai
a1 a2
P a
i-1
L
void lbcr (JD *p,int x)
{ / * P */
JD *s; /* */
s=(JD *)malloc(sizeof(JD )); /* */
s->data=x;
s->next=p->next;
p->next=s;
return OK;
}
S
anai
a1 a2
P a
i-1
x
L
void lbcr (JD *p,int x)
{ / * P */
JD *s; /* */
s=(JD *)malloc(sizeof(JD )); /* */
s->data=x;
s->next=p->next;
p->next=s;
return OK;
}
S
anai
a1 a2
P a
i-1
x
L
void lbcr (JD *p,int x)
{ / * P */
JD *s; /* */
s=(JD *)malloc(sizeof(JD )); /* */
s->data=x;
s->next=p->next;
p->next=s;
return OK;
}
S
anai
a1 a2
P
ai-1
x
L
void lbcr (JD *p,int x)
{ / * P */
JD *s; /* */
s=(JD *)malloc(sizeof(JD )); /* */
s->data=x;
s->next=p->next;
p->next=s;
return OK;
}
void lbsc(JD *p) /* p */
{ JD *q;
if(p->next !=NULL)
{ q=p->next ; / * qp */
p->next=q->next; /* p */
free(q); /* */
}
}
ai-1a1 ai ai+1
L p
void lbsc(JD *p) /* p */
{ JD *q;
if(p->next !=NULL)
{ q=p->next ; / * qp */
p->next=q->next; /* p */
free(q); /* */
}
}
ai-1a1 ai ai+1
L p
void lbsc(JD *p) /* p */
{ JD *q;
if(p->next !=NULL)
{ q=p->next ; / * qp */
p->next=q->next; /* p */
free(q); /* */
}
} a1
ai-1a1 ai ai+1
L p q
void lbsc(JD *p) /*p */
{ JD *q;
if(p->next !=NULL)
{ q=p->next ; / * qp */
p->next=q->next; /* p */
free(q); /* */
}
}
ai-1a1 ai ai+1
L p q
void lbsc(JD *p) /*p */
{ JD *q;
if(p->next !=NULL)
{ q=p->next ; / * qp */
p->next=q->next; /* p */
free(q); /* */
}
}
ai-1a1 ai ai+1
L p
void lbsc(JD *p) /*p */
{ JD *q;
if(p->next !=NULL)
{ q=p->next ; / * qp */
p->next=q->next; /* p */
free(q); /* */
}
}
h,x
JD *lbcz (JD *h,int x)
{ JD *p;
p=h;
while (p!=NULL && p->data!=x) p=p->next;
return(p);
}
3.
3.
a1 a2 ana3L …..
a1 a2 ana3L …..
4.
data nextbefore
5.
·
·
·
·
·
73#5 m h
Pi Ni link
data
P1 > … > Pi-1 > Pi >… > P k
P1 N1?Pi-1 Ni-1 Pi Ni Pk Nk ^?
Pi-1 > h > Pi
h m
P73#8 0”
1-1
main()
{ int x,num1=0,num2=0;
printf("input num");
scanf("%d",&x);
while(x!=0) {
if(x>0) num1=num1+1;
else num2=num2+1;
scanf("%d",&x);}
printf("Positive num is,%d\n",num1);
printf("Negative num is,%d\n",num2);}
2 3 4 5 –10 –89 20 66 0
Positive num is,6
Negative num is,2
L
S
2 8375 ^
P R
(1) L=P->link;
2 8375 ^
P R S
L
L
9.,.
L
S
2 8375 ^
P R
(2) R->data=P->data;
2 8575 ^
P R S
(3) R->data=P->link->data;
2 8775 ^
P R S
L
S
2 8375 ^
P R
(4) P->link->link->link->data=P->data;
2 5375 ^
P R S
L
S
2 8375 ^
P R
(5) T=P;
while(T!=NULL)
{ T->data=(T->data)*2;
T=T->link; }
L
S
2 ^
P R
10 14 6 16
L
S
2 8375 ^
P R
(6) T=P;
while(T->link!=NULL)
{ T->data=(T->data)*2;
T=T->link; }
L
S
2 ^
P R
10 14 6 8
L
S
2 8375 ^
P R
(7) P=(JD*)malloc(sizeof(JD));
P->data=10;
R->link=P;
P->link=S;
L
S
2 8375 ^
P R
(7) P=(JD*)malloc(sizeof(JD));
P->data=10;
R->link=P;
P->link=S;
P
L
S
2 8375 ^
P R
L
S
2 8375 ^
P R
(7) P=(JD*)malloc(sizeof(JD));
P->data=10;
R->link=P;
P->link=S;
P 10
L
S
2 8375 ^
P R
L
S
2 8375 ^
P R
(7) P=(JD*)malloc(sizeof(JD));
P->data=10;
R->link=P;
P->link=S;
L
S
2 8375 ^
R
P 10
L
S
2 8375 ^
P R
(7) P=(JD*)malloc(sizeof(JD));
P->data=10;
R->link=P;
P->link=S;
L
S
2 8375 ^
R
P 10
L
S
2 8375 ^
P R
(8) T=L;
T->link=P->link;
free(P);
L
S
2 837 ^
P
RT
5
L
S
2 8375 ^
P R
(9) S->link=L;
L
S
2 8375
P R
S->link= =L S.
L
S
2 8375 ^
P R
865
9761059 95 97.6
2.2
n
a1a2…… ai…… an
nn=0
2.2.1
2.
1.
3.
2.2.2
1.
2.
1.
……..
……..
b
b+m
b+(i-1)*m
b+(maxlen-1)*m
Loc(i)=b +i-1)*m
()
……
……
0
1
i
——C.
#define M 100 /*M100M*/
int V[M]; /*V*/
iai
Loc(ai)=Loc(a1)+(i-1)*m
V[]
V[ ]
…..
a2
a1
an
…..
ai+1
ai
0
1
i-1
i
n-1
1- 1
ai-1…..a2a1 alength
…
ai+1ai
x
ai-1…..a2a1 ai ai+1 … alength alength… …ai+1ix
int insq(int iint x,int V[ ],int M,int *p/ **/
{ /*Vi xi 1? i? n */
int nj
n=*p; / **/
ifn==M) / *Mp */
{ printf("overflow \n"); return (0);}
if((i<1) (i>n+1))
{printf("i is error \n");return (0);} /*i */
else { for (j=n; j>=i; j- -) V[j]=V[j-1]; /**/
V[j]=x; /* x */
p=++n; /* 1,p */
return (1);
}
}
viod main( )
{ int M=10;n=4; /*M,n,*/
int result,k;
static int V[10]={3,5,7,10}; /* */
result=insq(2,4,V,10,&n); /*,24*/
if ( result==1) { printf ("success ! \n");
for (k=0; k<n; k++) printf ("%d",V[k]);}
else printf("failure!");
}
:
success! 3 4 5 7 10
1- 2
int delsq(int i,int V[ ],int *p
{ /*Vi */
int n,j;
n=*p;
ifi<1 i>n
{ printf("This element is not in the list \n"); return (0);}
else { for (j=i;j<n;j++) V[j-1]=V[j];/**/
*p=--n; /*1*/
return (1);
}
}
2,
ZHAOQIANSUNLIZHOUWUZHENGWANG
:
a1 a2 ana3L …..
C
2,
data next
typedef struct LNode
{
int data;
Struct LNode *next;
} JD;
ba
ba
x
P
P
S
P
ba
ba
x
anai
a1 a2
P
P
ai-1
x
L
S
anai
a1 a2
P a
i-1
L
void lbcr (JD *p,int x)
{ / * P */
JD *s; /* */
s=(JD *)malloc(sizeof(JD )); /* */
s->data=x;
s->next=p->next;
p->next=s;
return OK;
}
anai
a1 a2
P a
i-1
L
void lbcr (JD *p,int x)
{ / * P */
JD *s; /* */
s=(JD *)malloc(sizeof(JD )); /* */
s->data=x;
s->next=p->next;
p->next=s;
return OK;
}
S
anai
a1 a2
P a
i-1
x
L
void lbcr (JD *p,int x)
{ / * P */
JD *s; /* */
s=(JD *)malloc(sizeof(JD )); /* */
s->data=x;
s->next=p->next;
p->next=s;
return OK;
}
S
anai
a1 a2
P a
i-1
x
L
void lbcr (JD *p,int x)
{ / * P */
JD *s; /* */
s=(JD *)malloc(sizeof(JD )); /* */
s->data=x;
s->next=p->next;
p->next=s;
return OK;
}
S
anai
a1 a2
P
ai-1
x
L
void lbcr (JD *p,int x)
{ / * P */
JD *s; /* */
s=(JD *)malloc(sizeof(JD )); /* */
s->data=x;
s->next=p->next;
p->next=s;
return OK;
}
void lbsc(JD *p) /* p */
{ JD *q;
if(p->next !=NULL)
{ q=p->next ; / * qp */
p->next=q->next; /* p */
free(q); /* */
}
}
ai-1a1 ai ai+1
L p
void lbsc(JD *p) /* p */
{ JD *q;
if(p->next !=NULL)
{ q=p->next ; / * qp */
p->next=q->next; /* p */
free(q); /* */
}
}
ai-1a1 ai ai+1
L p
void lbsc(JD *p) /* p */
{ JD *q;
if(p->next !=NULL)
{ q=p->next ; / * qp */
p->next=q->next; /* p */
free(q); /* */
}
} a1
ai-1a1 ai ai+1
L p q
void lbsc(JD *p) /*p */
{ JD *q;
if(p->next !=NULL)
{ q=p->next ; / * qp */
p->next=q->next; /* p */
free(q); /* */
}
}
ai-1a1 ai ai+1
L p q
void lbsc(JD *p) /*p */
{ JD *q;
if(p->next !=NULL)
{ q=p->next ; / * qp */
p->next=q->next; /* p */
free(q); /* */
}
}
ai-1a1 ai ai+1
L p
void lbsc(JD *p) /*p */
{ JD *q;
if(p->next !=NULL)
{ q=p->next ; / * qp */
p->next=q->next; /* p */
free(q); /* */
}
}
h,x
JD *lbcz (JD *h,int x)
{ JD *p;
p=h;
while (p!=NULL && p->data!=x) p=p->next;
return(p);
}
3.
3.
a1 a2 ana3L …..
a1 a2 ana3L …..
4.
data nextbefore
5.
·
·
·
·
·
73#5 m h
Pi Ni link
data
P1 > … > Pi-1 > Pi >… > P k
P1 N1?Pi-1 Ni-1 Pi Ni Pk Nk ^?
Pi-1 > h > Pi
h m
P73#8 0”
1-1
main()
{ int x,num1=0,num2=0;
printf("input num");
scanf("%d",&x);
while(x!=0) {
if(x>0) num1=num1+1;
else num2=num2+1;
scanf("%d",&x);}
printf("Positive num is,%d\n",num1);
printf("Negative num is,%d\n",num2);}
2 3 4 5 –10 –89 20 66 0
Positive num is,6
Negative num is,2
L
S
2 8375 ^
P R
(1) L=P->link;
2 8375 ^
P R S
L
L
9.,.
L
S
2 8375 ^
P R
(2) R->data=P->data;
2 8575 ^
P R S
(3) R->data=P->link->data;
2 8775 ^
P R S
L
S
2 8375 ^
P R
(4) P->link->link->link->data=P->data;
2 5375 ^
P R S
L
S
2 8375 ^
P R
(5) T=P;
while(T!=NULL)
{ T->data=(T->data)*2;
T=T->link; }
L
S
2 ^
P R
10 14 6 16
L
S
2 8375 ^
P R
(6) T=P;
while(T->link!=NULL)
{ T->data=(T->data)*2;
T=T->link; }
L
S
2 ^
P R
10 14 6 8
L
S
2 8375 ^
P R
(7) P=(JD*)malloc(sizeof(JD));
P->data=10;
R->link=P;
P->link=S;
L
S
2 8375 ^
P R
(7) P=(JD*)malloc(sizeof(JD));
P->data=10;
R->link=P;
P->link=S;
P
L
S
2 8375 ^
P R
L
S
2 8375 ^
P R
(7) P=(JD*)malloc(sizeof(JD));
P->data=10;
R->link=P;
P->link=S;
P 10
L
S
2 8375 ^
P R
L
S
2 8375 ^
P R
(7) P=(JD*)malloc(sizeof(JD));
P->data=10;
R->link=P;
P->link=S;
L
S
2 8375 ^
R
P 10
L
S
2 8375 ^
P R
(7) P=(JD*)malloc(sizeof(JD));
P->data=10;
R->link=P;
P->link=S;
L
S
2 8375 ^
R
P 10
L
S
2 8375 ^
P R
(8) T=L;
T->link=P->link;
free(P);
L
S
2 837 ^
P
RT
5
L
S
2 8375 ^
P R
(9) S->link=L;
L
S
2 8375
P R
S->link= =L S.
L
S
2 8375 ^
P R