欢迎来到天天文库
浏览记录
ID:40247162
大小:1.02 MB
页数:106页
时间:2019-07-29
《数据结构算法——Visual C++ 6.0程序集 第7章》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、数据结构算法VisualC++6.0程序集侯识忠等编著中国水利水电出版社第七章排序7、0桶排序(bucketsort.cpp)//桶排序bucketsort.cpp#include#include#include#include//欲桶排序的数组长度constintSIZE=12;voidbucketSort(int[]);voiddistributeElements(int[],int[][SIZE],int);voidcollectElements(int[],i
2、nt[][SIZE]);intnumberOfDigits(int[],int);voidzeroBucket(int[][SIZE]);voidmain(){cout<<"bucketsort.cpp运行结果:";intarray[SIZE];cout<<"原数组:";srand(time(0));for(inti=0;i3、排序后数组:";for(intj=0;j4、将桶数组初始化为0if(i!=totalDigits)zeroBucket(bucket);for(intj=0;jlargest)largest=b[i];while(largest!=0){++digits;largest/=10;}5、returndigits;}//将单下标数组的每个值放到桶数组的行中voiddistributeElements(inta[],intbuckets[][SIZE],intdigit){intdivisor=10,bucketNumber,elementNumber;for(inti=1;i6、cketNumber][0];buckets[bucketNumber][elementNumber]=a[k];}}//将桶数组的值复制回原数组voidcollectElements(inta[],intbuckets[][SIZE]){intsubscript=0;for(inti=0;i<10;++i)for(intj=1;j<=buckets[i][0];++j)a[subscript++]=buckets[i][j];}//将桶数组初始化为0voidzeroBucket(intbuckets[][SIZE]){for(inti=0;i<17、0;++i)for(intj=0;j#include#include#include#defineMAXI10typedefintKeyType;typedefintElemType;structrec{KeyTypekey;ElemTypedata;};typedefrecsqlist[MAXI];classcharu{pu8、blic:charu(sqlista,intm):n(m){for(inti=0;i
3、排序后数组:";for(intj=0;j4、将桶数组初始化为0if(i!=totalDigits)zeroBucket(bucket);for(intj=0;jlargest)largest=b[i];while(largest!=0){++digits;largest/=10;}5、returndigits;}//将单下标数组的每个值放到桶数组的行中voiddistributeElements(inta[],intbuckets[][SIZE],intdigit){intdivisor=10,bucketNumber,elementNumber;for(inti=1;i6、cketNumber][0];buckets[bucketNumber][elementNumber]=a[k];}}//将桶数组的值复制回原数组voidcollectElements(inta[],intbuckets[][SIZE]){intsubscript=0;for(inti=0;i<10;++i)for(intj=1;j<=buckets[i][0];++j)a[subscript++]=buckets[i][j];}//将桶数组初始化为0voidzeroBucket(intbuckets[][SIZE]){for(inti=0;i<17、0;++i)for(intj=0;j#include#include#include#defineMAXI10typedefintKeyType;typedefintElemType;structrec{KeyTypekey;ElemTypedata;};typedefrecsqlist[MAXI];classcharu{pu8、blic:charu(sqlista,intm):n(m){for(inti=0;i
4、将桶数组初始化为0if(i!=totalDigits)zeroBucket(bucket);for(intj=0;jlargest)largest=b[i];while(largest!=0){++digits;largest/=10;}
5、returndigits;}//将单下标数组的每个值放到桶数组的行中voiddistributeElements(inta[],intbuckets[][SIZE],intdigit){intdivisor=10,bucketNumber,elementNumber;for(inti=1;i6、cketNumber][0];buckets[bucketNumber][elementNumber]=a[k];}}//将桶数组的值复制回原数组voidcollectElements(inta[],intbuckets[][SIZE]){intsubscript=0;for(inti=0;i<10;++i)for(intj=1;j<=buckets[i][0];++j)a[subscript++]=buckets[i][j];}//将桶数组初始化为0voidzeroBucket(intbuckets[][SIZE]){for(inti=0;i<17、0;++i)for(intj=0;j#include#include#include#defineMAXI10typedefintKeyType;typedefintElemType;structrec{KeyTypekey;ElemTypedata;};typedefrecsqlist[MAXI];classcharu{pu8、blic:charu(sqlista,intm):n(m){for(inti=0;i
6、cketNumber][0];buckets[bucketNumber][elementNumber]=a[k];}}//将桶数组的值复制回原数组voidcollectElements(inta[],intbuckets[][SIZE]){intsubscript=0;for(inti=0;i<10;++i)for(intj=1;j<=buckets[i][0];++j)a[subscript++]=buckets[i][j];}//将桶数组初始化为0voidzeroBucket(intbuckets[][SIZE]){for(inti=0;i<1
7、0;++i)for(intj=0;j#include#include#include#defineMAXI10typedefintKeyType;typedefintElemType;structrec{KeyTypekey;ElemTypedata;};typedefrecsqlist[MAXI];classcharu{pu
8、blic:charu(sqlista,intm):n(m){for(inti=0;i
此文档下载收益归作者所有