Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void w(int j, int* A, int n)
- {
- if(j > 0)
- if(A[j] < A[j - 1])
- {
- int v = A[j];
- A[j] = A[j - 1];
- A[j - 1] = v;
- w(j - 1, A, n);
- }
- }
- void w_2(int j, int* A, int n)
- {
- while(j > 0)
- if(A[j] < A[j - 1])
- {
- int v = A[j];
- A[j] = A[j - 1];
- A[j - 1] = v;
- --j;
- }
- }
- void algorytm_s1(int* A, int n)
- {
- for(int i = 1; i < n; ++i)
- w(i, A, n);
- }
- void algorytm_s2(int* A, int n)
- {
- for(int i = n - 1; i > 0; --i)
- w(i, A, n);
- }
- void wypisz_tablice(int* tab, int n)
- {
- for(int i = 0; i < 10; ++i)
- cout << tab[i] << '\t';
- cout << endl;
- }
- int main()
- {
- int A[10] = {2, 4, 6, 8, 10, 9, 7, 5, 3, 1};
- wypisz_tablice(A, 10);
- algorytm_s2(A, 10);
- wypisz_tablice(A, 10);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement