当前位置:首页 > 数据结构实验报告——排序
}
}
}
}
parray[0]=parray[j]; parray[j]=parray[j+1]; parray[j+1]=parray[0]; exchange=j; movetimes[2]+=3;
return 0;
/***********************************************************快速排序**********************************************************************/ int Sort::QuickSort(long int parray[]) { }
int Sort::QuickSortRecursion(long int parray[], int first=1, int end=Max) {
if (first QuickSortRecursion(parray,1, Max); return 0; int pivot=QuickSortPatition(parray, first, end); QuickSortRecursion(parray, first, pivot-1);//左侧子序列排序 QuickSortRecursion(parray, pivot+1, end); //右侧子序列排序 } int Sort::QuickSortPatition(long int r[], int first, int end ) { int i=first; int j=end; int temp; } return 0; while (i { while (i { j--; comparetimes[3]++; //右侧扫描 } if (i { temp=r[i]; //将较小记录交换到前面 r[i]=r[j]; r[j]=temp; i++; movetimes[3]+=3; } while (i { i++; comparetimes[3]++; //左侧扫描 } if (i { temp=r[j]; r[j]=r[i]; r[i]=temp; //将较大记录交换到后面 j--; } movetimes[3]+=3; } return i; //i为轴值记录的最终位置 } /***********************************************************选择排序**********************************************************************/ int Sort::SelectSort(long int parray[]) { int i,j,index,temp; for (i=1; i { index=i; for (j=i+1; j<=Max; j++) { comparetimes[4]++; //在无序区中选取最小记录 if (parray[j] index=j; } if (index!=i) } /*************************************************************堆排序***********************************************************************/ int Sort::HeapSort(long int parray[]) { { temp=parray[i]; parray[i]=parray[index]; parray[index]=temp; movetimes[4]+=3; } } return 0;
共分享92篇相关文档