slide1
Download
Skip this Video
Download Presentation
习题讲解

Loading in 2 Seconds...

play fullscreen
1 / 22

习题讲解 - PowerPoint PPT Presentation


  • 132 Views
  • Uploaded on

习题讲解. 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 表长

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

PowerPoint Slideshow about ' 习题讲解' - oneida


An Image/Link below is provided (as is) to download presentation

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
slide1

习题讲解

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中一个相应字符大

}

slide2

习题讲解

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;

}

}

slide3

{ if(a[i]==a[j])

{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)

slide4
习题讲解1. 4

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

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

slide5

习题讲解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); }

slide6

习题讲解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_add();

int poly_multiply(polya,an,polyb,

bn,p_ch,p_ct)

TERM polya[],polyb[];

int an,bn,*p_ch,*p_ct;

slide7

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

}

slide8

习题讲解1.5

free=sstart;

if(poly_add(ah,at,bh,bt,p_ch,p_ct)) return(1);

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

slide9

习题讲解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; }

}

slide10

习题讲解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);

}

slide11

习题讲解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);

}

slide12

习题讲解1.9

#define N 100

int q[N];

int head=-1,tail=0;

int en_queue2(x)

int x;

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

q[tail++]=x;

return(0);

}

int de_queue2(p_y)

int *p_y;

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

*p_y=q[head++];

return(0);

}

slide13

习题讲解1.10

abc*d/+efg^^+h+

ab+cd/*ef^gh+^+

slide14

习题讲解1.11

typedef struct node {char data;

struct node *link;

} NODE;

NODE *head;

int count(head)

NODE *head;

{ int n=0;

NODE *p;

if(head==NULL) return(0);

p=head;

while(p->link!=NULL)

{ p=p->link;

n++; }

n++;

return(n);

}

slide15

习题讲解1.12

void reverse(p_head)

NODE **p_head;

{

NODE *p,*q,*r;

if(*p_head==NULL) return;

p=NULL;

q=*p_head;

while(q!=NULL)

{

r=q->link;

q->link=p;

p=q;

q=r;

}

*p_head=p;

}

slide16

习题讲解1.13

void insert1(p_head,a,b)

NODE **p_head;

char a, b;

{ NODE *p,*q;

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

q->data=a;

q->link=NULL;

if(*p_head==NULL)

*p_head=q;

else {

p=*p_head;

slide17

习题讲解1.13

if(p->data==b){

*p_head=q;

q->link=p; }

else {

while(p->link!=NULL&&p->link->data!=b)

p=p->link;

if(p->link->data==b) {

q->link=p->link;

p->link=q; }

else

p->link=q; } }

}

slide18

习题讲解1.14

int delete1(p_head,a)

NODE **p_head;

char a;

{ NODE *p,*q:

q=*p_head;

if(q==NULL||q->link==NULL) return (1);

if(q->link->data==a) {

*p_head=q->link;

free(q);

return(0); }

slide19

习题讲解1.14

while(q->link!=NULL&&q->link->data!=a) {

p=q;

q=q->link; }

if(q->link->data==a) {

p->link=q->link;

free(q);

return(0); }

else

return(1); }

slide20
typedef struct node {int data;

struct node *link;

}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->link=px;

pz=px;

px=px->link;

pz->link=py;

pz=py;

py=py->link;

}

pz->link=px?px:py;

pz=zh;

zh=zh->link;

free(pz);

*pxh=NULL;

*pyh=NULL;

return(zh);

}

习题讲解1.15
slide21
NODE *xh, *yh;

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->link=px;

pz=px;

px=px->link;

}

else

{

pz->link=py;

pz=py;

py=py->link;

}

习题讲解1.16
slide22
while(px->data>=pz->data)

{

pz->link=px;

pz=px;

px=px->link;

}

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

{

pz->link=pz;

pz=py;

py=py->link;

}

pz->link=zh->link;

pz=zh;

zh=zh->link;

free(pz);

return(zh);

}

习题讲解1.16
ad