Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4. void uporzadkuj(vector<int> & wek){
  5.     int lpoczatku=0;
  6.     int lkonca=wek.size();
  7.     while(lpoczatku != lkonca){
  8.         if (wek[lpoczatku]%2==0 && wek[lkonca]%2==0){
  9.             lpoczatku++;
  10.         }else if(wek[lpoczatku]%2==0 && wek[lkonca]%2!=0){
  11.             lpoczatku++;
  12.             lkonca--;
  13.         }else if(wek[lpoczatku]%2!=0 && wek[lkonca]%2==0){
  14.             swap(wek[lpoczatku], wek[lkonca]);
  15.             lpoczatku++;
  16.             lkonca--;
  17.         }else if(wek[lpoczatku]%2!=0 && wek[lkonca]%2!=0){
  18.             lkonca--;
  19.         }
  20.     }
  21. }
  22. int main(){
  23.     vector <int> test(8);
  24.     test[0] = 1;
  25.     test[1] = 2;
  26.     test[2] = 3;
  27.     test[3] = 4;
  28.     test[4] = 5;
  29.     test[5] = 6;
  30.     test[6] = 7;
  31.     test[7] = 8;
  32.     cout<<"Tablica testowa: "<<endl;
  33.     for(int i=0; i<test.size();i++){
  34.         cout<<test[i]<<endl;
  35.     }
  36.     cout<<"Tablica uporzadkowana funkcja 'uporzadkuj', ktora sortuje najpierw parzyste, nastepnie nieparzyste: "<<endl;
  37.     uporzadkuj(test);
  38.     for(int i=0; i<test.size();i++){
  39.         cout<<test[i]<<endl;
  40.     }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement