1 / 22

# 习题讲解 - PowerPoint PPT Presentation

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about ' 习题讲解' - oneida

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### 习题讲解

1．1

int compare(a,b,m,n)

int a[],b[],m,n;

{ int i,t;

if(m>=n) t=n; // 选定循环次数t

else t=m;

for(i=0;i<t&&a[i]==b[i];i++); //比较，空语句

if (i==m&&i==n) return(0); //相等

else if(i==m) return(-1); //b表长

else if(i==n) return (1); //a表长

if(a[i]>b[i]) return(1); //a中一个相应字符大

else return(-1); //b中一个相应字符大

}

### 习题讲解

0 1

n-1

t

1.2

void invert(a,n)

int a[],n;

{ int i,t,s;

t=n/2;

for(i=0;i<t;i++)

{ s=a[i];

a[i]=a[n-i-1];

a[n-i-1]=s;

}

}

{k=j;

while(a[k]!=-32768)

{ a[k]=a[k+1];

k++;

}

n--;

j--;

}

j++;

}

i++;

}

*p_n=n;

}

### 习题讲解

1.3

#define MAXN 100

int a[MAXN];

int n;

void de_r(a,p_n)

int a[];

int *p_n;

{ int i,j,k,n;

n=*p_n;

a[n]=-32768;

i=0;

while(a[i]!=-32768)

{ j=i+1;

while(a[j]!=-32768)

8x60+6x50+4x25+2x10+1

=((((8x60-50+6)x50-25+4)x25-10+2)x10-0+1)

### 习题讲解1. 4

#define MAXN 100

typedef struct node {float coef;

int exp; }TERM;

TERM poly[MAXN];

int ah,at;

float poly_val(ah,at,x)

int ah,at;

float x;

{ int i,j;

float s,t=1;

s=poly[ah].coef;

for(i=ah;i<at;i++)

{ for(j=poly[i+1].exp,t=1;j<poly[i].exp;j++)

t*=x;

s=s*t+poly[i+1].coep; }

return(s); }

### 习题讲解1.5

#define MAXN 100

type struct {int coef;

int exp;

}TERM;

TERM polya[MAXN],polyb[MAXN],poly[MAXN];

int ch,ct,sstart,an,bn,free;

int append();

int poly_multiply(polya,an,polyb,

bn,p_ch,p_ct)

TERM polya[],polyb[];

int an,bn,*p_ch,*p_ct;

ah at bh bt sstart

### 习题讲解1.5

*p_ch *p_ct

{ int ah,at,bh,bt,i,j,k;

ah=0;

at=an-1;

bh=bt=an;

sstart=an+an*bn;

i=0;

while(i<bn)

{ j=0;

while(j<an)

{poly[j].coef=polyb[i].coef*polya[j].coef;

poly[j].exp=polyb[i].exp+polya[j].exp;

j++;

}

### 习题讲解 sstart 1.5

free=sstart;

k=*p_ch;

while(k<=*p_ct)

poly[k-an*bn]=poly[k++];

bt=k-an*bn-1;

i++;

}

return(0);

}

ah at bh bt sstart

*p_ch *p_ct

### 习题讲解 sstart 1.6

#define MAXN 100

void printring(a,n,i,k)

int a[MAXN],n,i,k;

{ int b[MAXN],j,l;

for(j=0;j<n;j++) b[j]=0;

i--;

for(j=0;j<n;j++)

{ l=0;

while(l<k)

{ i=(i+1)%n;

if(b[i]!=1)

l++;}

printf(“%d ”,a[i]);

b[i]=1; }

}

### 习题讲解 sstart 1.8

#define MAXN 100

int stack[MAXN];

int top1=-1,top2=MAXN;

int push(x,i)

int x,i;

{

if(i<1||i>2) return(-1);

if(top2==top1+1) return(1);

if(i==1) stack[++top1]=x;

else stack[--top2]=x;

return(0);

}

### 习题讲解 sstart 1.8

int pop(p_y,i)

int *p_y,i;

{ if(i<1||i>2) return(-1);

if(i==1)

if(top1==-1) return(1);

else *p_y=stack[top1--];

else

if(top2=MAXN) return(-1);

else *p_y=stack[top2++];

return(0);

}

### 习题讲解 sstart 1.9

#define N 100

int q[N];

int en_queue2(x)

int x;

{ if(tail==N) return(1);

q[tail++]=x;

return(0);

}

int de_queue2(p_y)

int *p_y;

return(0);

}

abc*d/+efg^^+h+

ab+cd/*ef^gh+^+

### 习题讲解 sstart 1.11

typedef struct node {char data;

} NODE;

{ int n=0;

NODE *p;

n++; }

n++;

return(n);

}

{

NODE *p,*q,*r;

p=NULL;

while(q!=NULL)

{

p=q;

q=r;

}

}

### 习题讲解 sstart 1.13

char a, b;

{ NODE *p,*q;

q=(NODE *)malloc(sizeof(NODE));

q->data=a;

else {

if(p->data==b){

else {

else

}

char a;

{ NODE *p,*q:

free(q);

return(0); }

### 习题讲解 sstart 1.14

p=q;

free(q);

return(0); }

else

return(1); }

}NODE;

NODE *xh, *yh;

NODE *merge_l(pxh,pyh)

NODE **pxh,**pyh;

{

NODE *px, *py, *pz, *zh;

zh=(NODE *)malloc(sizeof(NODE));

pz=zh;

px=*pxh;

py=*pyh;

while(px&&py)

pz=px;

pz=py;

}

pz=zh;

free(pz);

*pxh=NULL;

*pyh=NULL;

return(zh);

}

NODE *xh, *yh; sstart

NODE *merge_c_l(xh, yh)

NODE *xh, *yh;

{

NODE *px, *py, *pz, *zh;

if(xh==NULL) return(yh);

if(yh==NULL) return(xh);

zh=(NODE *)malloc(sizeof(NODE));

pz=zh;

pz->data=-32768;

px=xh;

py=yh;

while(px->data>=pz->data&&

py->data>=pz->data)

if(px->data<=py-data)

{

pz=px;

}

else

{

pz=py;

}

{

pz=px;

}

while(py->data>=pz->data)

{

pz=py;

}