求解,找错误,大神帮帮忙!
数据结构吧
全部回复
仅看楼主
level 1
#include<stdio.h>
typedef int keytype;
typedef struct
{
keytype key;
}rcdtype;
const maxsize=7;
const length=8;
typedef struct
{
rcdtype r[maxsize+1];
int length;
}sqlist;
void creat(sqlist &C,int *c,int n)
{
int i;
for(i=1;i<=n;i++)
C.r[i].key=c[i-1];
}
void bubblesort(sqlist &l)
{
int i,j,last;
rcdtype w;
i=l.length;
while(i>1)
{
last=1;
for(j=1;j<i;j++)
{
if(l.r[j+1].key<l.r[j].key)
{
w=l.r[j];l.r[j]=l.r[j+1];l.r[j+1]=w;
last=j;
}
}
i=last;
}
}
void print(sqlist &D)
{
int j;
for(j=1;j<=maxsize;j++)
printf("%d ",D.r[j].key);
printf("\n");
}
void main()
{
sqlist A;
int a[7]={3,5,2,4,1,7,10};
creat(A,a,7);
bubblesort(A);
print(A);
}
2014年01月03日 08点01分 1
level 1
要求运行之后非递减输出,可我运行之后还是跟输入的时候一个样没变,咋回事?
2014年01月03日 08点01分 2
level 1
今天做了8道,就这个运行不出来,看了好几遍了都没看出来![不高兴]
2014年01月03日 08点01分 3
level 1
求解!!!
2014年01月03日 09点01分 4
level 1
求解!!!
2014年01月03日 09点01分 5
level 1
求解!!!
2014年01月03日 09点01分 6
level 1
求解!!!
2014年01月03日 11点01分 7
level 10
你这个冒泡排序不忍看啊,交换值的时候,是交换的key,而不是rcdtype这个结构体,另外直接两重循环就完了,不要声明过多的局部变量,c++没有gc
2014年01月04日 06点01分 8
1