mirror of
https://inf-git.fh-rosenheim.de/studavrije7683/cplusplus-training.git
synced 2025-04-20 05:59:54 +00:00
47 lines
679 B
C++
47 lines
679 B
C++
#include <iostream>
|
|
#include <cstdlib>
|
|
|
|
using namespace std ;
|
|
|
|
int main ()
|
|
{
|
|
int a [10] , i , zw , change ;
|
|
|
|
cout << "unsortiert: ";
|
|
for ( i =0; i <10; i ++)
|
|
{
|
|
a [i] = rand()%100;
|
|
cout << a [i] << " ";
|
|
}
|
|
|
|
// sortieren ( und dabei ausgeben ...)
|
|
do
|
|
{
|
|
cout << endl << "Zwischenschritt: ";
|
|
change=0; // keine Vertauschung noetig
|
|
for (i=0; i<9; i++)
|
|
if ( a [i] > a [i+1])
|
|
{
|
|
zw = a[i];
|
|
a[i] = a[i+1];
|
|
a[i+1] = zw;
|
|
change = 1; // Vertauschung
|
|
}
|
|
for (i=0; i<10; i++) cout << a [i] << " ";
|
|
}
|
|
while (change);
|
|
|
|
cout << endl;
|
|
|
|
cout << "sortiert: ";
|
|
for ( i =0; i <10; i ++)
|
|
{
|
|
cout << a [i] << " ";
|
|
}
|
|
|
|
cout << endl;
|
|
|
|
system("pause");
|
|
return 0;
|
|
}
|