PDA

View Full Version : selection sort và bubble sort đệ quy



xiah1488
01-05-2008, 21:54
Mình dùng đệ quy cho bubble sort và selection sort,mong các bạn góp ý cho mình với,thanks nhiều
code:
//------------------------------------------------------------
//Bubble sort:
//
void BubbleSort(int *Arr,int startIndex,int n)
{
if(startIndex>=n-1)
return ;
for(int j=n-1;j>startIndex ;j--)
if(Arr[j]<Arr[j-1])
{
HoanVi(Arr[j],Arr[j-1]);
}
BubbleSort(Arr,startIndex+1,n);


}
//selection sort
void SelectionSort(int *Arr, int startIndex,int n)
{
if(startIndex >=n-1)
return ;
int minIndex=startIndex;
for(int i=startIndex;i<n;i++)
{
if (Arr[i]<Arr[minIndex ])
minIndex=i;
}
HoanVi(Arr[minIndex ],Arr[startIndex ]);
SelectionSort(Arr,startIndex+1, n);

}
//--------------------------------------------------------