[[swap]]
 
#include <iostream>
 
using namespace std;
 
void swap (int & a, int & b)
{
    // cout << "na vstupu a=" << a << ", b=" << b << endl;
    int t = a;
    a = b;
    b = t;
    // cout << "na vystupu a=" << a << ", b=" << b << endl;
}
 
const int N = 10;
 
int a[N] = { 10, 40, 20, 70, 30, 80, 40 };
 
int main()
{
    bool change = true;
 
    while (change)
    {
        change = false;
        for (int i = 1; i < N; i++)
           {
              if (a[i-1] > a[i])
              {
                  swap (a[i-1], a[i]);
                  change = true;
              }
           }
 
        for (int i = 0; i < N; i++)
            cout << a[i] << " ";
        cout << endl;
    }
 
    return 0;
}
 
swap.txt · Last modified: 2018/10/25 16:10 by 147.32.8.115
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki