Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- using namespace std;
- void uporzadkuj(vector<int> & wek){
- int lpoczatku=0;
- int lkonca=wek.size();
- while(lpoczatku != lkonca){
- if (wek[lpoczatku]%2==0 && wek[lkonca]%2==0){
- lpoczatku++;
- }else if(wek[lpoczatku]%2==0 && wek[lkonca]%2!=0){
- lpoczatku++;
- lkonca--;
- }else if(wek[lpoczatku]%2!=0 && wek[lkonca]%2==0){
- swap(wek[lpoczatku], wek[lkonca]);
- lpoczatku++;
- lkonca--;
- }else if(wek[lpoczatku]%2!=0 && wek[lkonca]%2!=0){
- lkonca--;
- }
- }
- }
- int main(){
- vector <int> test(8);
- test[0] = 1;
- test[1] = 2;
- test[2] = 3;
- test[3] = 4;
- test[4] = 5;
- test[5] = 6;
- test[6] = 7;
- test[7] = 8;
- cout<<"Tablica testowa: "<<endl;
- for(int i=0; i<test.size();i++){
- cout<<test[i]<<endl;
- }
- cout<<"Tablica uporzadkowana funkcja 'uporzadkuj', ktora sortuje najpierw parzyste, nastepnie nieparzyste: "<<endl;
- uporzadkuj(test);
- for(int i=0; i<test.size();i++){
- cout<<test[i]<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement