然後還有壹個與程序相關的錯誤。只有寫這個程序的人知道如何解決這個錯誤。雖然我可以解決它,但它很麻煩,所以自己看看如何解決那個錯誤!
# include & ltiostream & gt
# include & ltcstdlib & gt
# include & ltctime & gt
#定義N 50
使用命名空間std
void InsertSort(int r[])
{ int x=0,y = 0;
for(int I = 1;我& ltn;i++)
{
int s = r[I];
int low = 0;
int high = I-1;
x++;
while(low & lt;=高)
{
int mid=(低+高)/2;
x++;
if(s & lt;r[mid])
{
高=中1;
y++;
}
其他
{
低= mid+1;
y++;
}
}
for(int j = I-1;j & gt=高+1;i++,j -)
{
r[j+1]= r[j];
y++;
}
r[高+1]= s;
y++;
}
cout & lt& lt”插入排序:“;
cout & lt& ltendl & lt& lt“* * *為了比較”
}
void BubbleSort(int r[])
{ int x=0,y = 0;
for(int I = 0;我& ltn-1;i++)
{
for(int j = 0;j & ltn-1-I;j++)
{ i++;
if(r[j]& gt;r[j+1])
{
int temp = r[j];
r[j]= r[j+1];
r[j+1]= temp;
y+= 3;
}
}
}
cout & lt& lt“冒泡法”:
cout & lt& ltendl & lt& lt“* * *為了比較”
}
void ShellSort(int r[])
{
int step = N/2;
int x=0,y = 0;
while(步驟& gt= 1)
{
for(int I = step;我& ltn;I+=步長)
{
for(int j=i-step,s = r[I];s & ltr[j]& amp;& ampj & gt=0;j-=步進,x++)
{
r[j+step]= r[j];
y++;
}
r[j+step]= s;
y++;
}
step/= 2;
}
cout & lt& lt”希爾排序:“;
cout & lt& ltendl & lt& lt“* * *為了比較”
}
void SelectSort(int r[])
{
int x=0,y = 0;
for(int I = 0;我& ltn-1;i++)
{
int s = I;
for(int j = I+1;j & ltn;j++)
{
if(r[s]& gt;r[j])
{
x++;
s = j;
}
}
如果(small_loc!= i)
{
int temp = r[I];
r[I]= r[s];
r[s]= temp;
y+= 3;
}
}
cout & lt& lt”選擇排序:“;
cout & lt& ltendl & lt& lt“* * *為了比較”
}
int Partition(int r[],int low,int high,int d[])
{
int pivot key = r[low];
int i =低;
int j =高;
while(我& ltj)
{
while(我& lt強生公司。& ampr[j]& gt;數據透視鍵){
j-;d[0]++;
}
如果(我& ltj){
r[I]= r[j];i++;d[1]++;
}
while(我& lt強生公司。& ampr[I]& lt;數據透視鍵){
i++;d[0]++;
}
如果(我& ltj){
r[j]= r[I];j-;d[1]++;
}
}
r[j]= pivot key;d[1]++;
返回j;
}
void QuickSort(int r[],int low,int high,int d[])
{
if(低& lt高)
{
int pivot=Partition(r,low,high,d);
QuickSort(r,low,pivot-1,d);
QuickSort(r,pivot+1,high,d);
}
cout & lt& lt"快速排序:";
cout & lt& ltendl & lt& lt“* * *為了比較”
}
int main()
{
int a[N];int d[2];
srand((無符號)時間(空));
a[N]= rand();
insert sort(a);
氣泡排序(a);
shell sort(a);
select sort(a);
快速排序(a,0,N,d);
返回0;
}