Contoh Array :
| 2 | 1 | 4 | 3 |
Setelah disorting :
| 1 | 2 | 3 | 4 |
Untuk mengetahui jawabannya maka berikut ini raptornya :
Silahkan download disini :
Download Raptor
Maka berikut ini listing programnya hasil generate from raptor :
#include iostream;
#include string;
using namespace std;
class bubblesort{
public:
void bubble (int x[100],int data);
};
void bubblesort:: bubble (int x[100],int data)
{
int temp;
int i;
int j;
i =1;
while (!(i>data))
{
j =i+1;
while (!(j>data))
{
if (x[i]>x[j])
{
temp =x[i];
x[i] = x[j];
x[j] = temp;
}
else
{
}
j =j+1;
}
i =i+1;
}
cout << "Sorting " << endl; i =1;
while (!(i>data))
{
cout << x[i] << endl; i =i+1;
}
}
int main()
{
bubblesort a;
string raptor_prompt_variable_zzyz;
int i;
int data;
int x[100];
raptor_prompt_variable_zzyz ="Banyak array : ";
cout << raptor_prompt_variable_zzyz;
cin >> data;
i =1;
while (!(i>data))
{
raptor_prompt_variable_zzyz ="input data : ";
cout << raptor_prompt_variable_zzyz;
cin >> x[i];
i =i+1;
}
cout<<endl;
a.bubble(x,data);
cout<<endl;
system("PAUSE");
return 0;
}
Semoga bermanfaat!!
Comment here