第一章
16
void Descend(int &x, int &y, int &z)
{
int t;
if(x<y) {t=x;x=y;y=t;}
if(x<z) {t=x;x=z;z=t;}
if(y<z) {t=y;y=z;z=t;}
弱不禁风的意思}
17
Status Fibonacci(int k, int m, int &f)
/* 求k阶斐波那契序列的第m项的值f */
{
int i,j,sum,temp[20];
if(k<2||m<0) return ERROR;
if(m<k-1) f=0;
el if(m==k-1) f=1;
el
{for(i=0;i<=k-2;i++)
temp[i]=0;
temp[k-1]=1;
for(i=k;i<=m;i++)
{sum=0;
for(j=i-k;j<i;j++)
sum+=temp[j];
temp[i]=sum;
}
f=temp[m];
}
return OK;
}// Fibonacci
18
void Scores(ResultType *result, ScoreType *score)
/* 求各校的男、女总分和团体总分, 并依次存入数组score */
/* 假设比赛结果已经储存在result[ ]数组中, */
/* 并以特殊记录 {"", male, ' ', "", 0 }(域scorce=0)*/
/* 表示结束 */
浴霸怎么安装
{
int i=0;
char s;
while(result[i].sport!=NULL)
{
switch(result[i].schoolname)
{
ca 'A':
score[0].totalscore+=result[i].score;
if(result[i].gender==male) score[0].malescore+=result[i].score;
el score[0].femalescore+=result[i].score;
break;
ca 'B':
score[1].totalscore+=result[i].score;
if(result[i].gender==male) score[1].malescore+=result[i].score;
el score[1].femalescore+=result[i].score;
break;
ca 'C':
score[2].totalscore+=result[i].score;
if(result[i].gender==male) score[2].malescore+=result[i].score;
el score[2].femalescore+=result[i].score;
break;
ca 'D':
score[3].totalscore+=result[i].score;
if(result[i].gender==male) score[3].malescore+=result[i].score;
el score[3].femalescore+=result[i].score;
break;
ca 'E':
score[4].totalscore+=result[i].score;
if(result[i].gender==male) score[4].malescore+=result[i].score;
el score[4].femalescore+=result[i].score;
break;
网恋的危害 }
i++;
}
for(s='A';s<='E';s++)
{
printf("School %c:\n",s);
printf("Total score of male:%d\n",score[i].malescore);
printf("Total score of female:%d\n",score[i].femalescore);
日本大逼 printf("Total score of all:%d\n\n",score[i].totalscore);
}
}
19
Status Series(int ARRSIZE, int a[])
幼儿智育/* 求i!*2^i序列的值并依次存入长度为ARRSIZE的数组a; */
项目职责
/* 若所有值均不超过MAXINT,则返回OK,否则返回OVERFLOW */
{
新生儿音乐100首必听
int last,i;
last=1;
for (i=1;i<=ARRSIZE;i++)
{
a[i-1]=last*2*i;
if (a[i-1]>MAXINT)
return OVERFLOW;
last=a[i-1];
}
return OK;
}
20
float Polynomial(int n, int a[], float x)不甚了解
/* 求一元多项式的值P(x)。 */
/* 数组a的元素a[i]为i次项的系数,i=0,...,n */
{
int j,i;
float y,s;
y=0;
for(j=n;j>0;j--)
y=x*(y+a[j]);
s=y+a[0];
return(s);
}
第二章
12
char Compare(SqList A, SqList B)
// 比较顺序表A和B,
// 返回'<', 若A<B;
// '=', 若A=B;
// '>', 若A>B
{
int i;
for(i=1;i<=A.length&&i<=B.length;i++)
if(A.elem[i]!=B.elem[i])
return A.elem[i]>B.elem[i]?'>':'<';
if(A.length==B.length) return '=';
return A.length>B.length?'>':'<';
}
14
int Length(LinkList L)
// Return the length of the linked list
// who head node is pointed by 'L'
{
LNode *p;
int k;
p=L;
for(k=0;(p->next)!=NULL;p=p->next,k++);
return k;
}
19
void DeleteSome(LinkList &L, ElemType mink, ElemType maxk)
/* Delete all the elements which value is between mink and */
/* maxk from the single sorted LinkList with head pointer L.*/
{
LinkList p,q,pre;
pre=L;
while(pre->next&&pre->next->data<=mink)