JS編譯的幾種情況要打;號
阿新 • • 發佈:2020-12-25
技術標籤:排序
#include <iostream>
using namespace std;
int num[20],len;
void quicksort(int left, int right)
{
int i, j, t, temp;
if(left > right)
return;
temp = num[left];
i = left;
j = right;
while(i != j)
{
while(num[j] >= temp && i < j)
j--;
while(num[i] <= temp && i < j)
i++;
if(i < j)
{
t = num[i];
num[i] = num[j];
num[j] = t;
}
}
for(int k=0;k<len;k++)
cout<<num[k]<<" ";//檢視排序過程
cout<< endl;
num[left] = num[i];
num[i] = temp;
quicksort(left, i-1);
quicksort(i+1, right);
}
int main()
{
int i=0;
cin>>num[i];
while(num[i]!=0)
{
i++;
cin>>num[i];
}
len=i;
quicksort(0,i-1);
cout<<"最終結果:"<<"\n" ;
for(i=0; i<len; i++)
cout<<num[i]<<" ";
return 0;
}
//小綿楊Yeanling