Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- int tab[10];
- int t[10];
- void scalaj(int start, int mid, int _end)
- {
- int i,j,q;
- for (i = start; i <= _end; i++)
- t[i]=tab[i];
- i = start; j = mid+1; q = start;
- while (i <= mid && j <= _end)
- {
- if (t[i] < t[j])
- tab[q++] = t[i++];
- else
- tab[q++] = t[j++];
- }
- while (i <= mid)
- tab[q++] = t[i++];
- }
- void sortuj(int start, int _end)
- {
- int mid;
- if (start<_end)
- {
- mid = (start+_end)/2;
- sortuj(start, mid);
- sortuj(mid+1, _end);
- scalaj(start, mid, _end);
- }
- }
- int main()
- {
- srand( time( NULL ) );
- cout << "Liczby przed posortowaniem" << endl;
- for(int i = 0; i < 10; i++)
- {
- tab[i] = (rand() % 10) + 1;
- cout << tab[i] << " ";
- }
- sortuj(0,9);
- cout << endl;
- cout << "Liczby po posortowaniu" << endl;
- for(int i = 0; i < 10; i++)
- {
- cout << tab[i] << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement