帮帮看哪里错了???
#include <iostream>using namespace std;
void bubblesort(int arr[], int len)
{
int temp;
for(int i=0; i<len-1; i++)
{
for(int j=0; len-i-1; j++)
{
if(arr > arr)
{
temp = arr;
arr = arr;
arr = temp;
}
}
}
}
int main(void)
{
int arr = {6, -1, 4, 3, 8};
bubblesort(arr, 5);
for(int i=0; i<5; i++)
cout << arr << ",";
cout << endl;
return 0;
}
225077 segmentation fault (core dumped)./a.out
没问题吧????? 第9行少了j< ,加上程序就能从小到大排序了 三楼正解
#include <iostream>
using namespace std;
void bubblesort(int arr[], int len)
{
int temp;
for(int i=0; i<len-1; i++)
{
for(int j=0; j<len-i-1; j++)
{
if(arr > arr)
{
temp = arr;
arr = arr;
arr = temp;
}
}
}
}
int main(void)
{
int arr = {6, -1, 4, 3, 8};
bubblesort(arr, 5);
for(int i=0; i<5; i++)
cout << arr << ",";
cout << endl;
return 0;
} 风过无痕1989 发表于 2020-10-18 09:08
第9行少了j< ,加上程序就能从小到大排序了
thank you!!! 川建军 发表于 2020-10-18 11:46
thank you!!!
不用客气,给个最佳答案就行了
页:
[1]