Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include<list>
  4. using namespace std;
  5.  
  6. void SortListToVector(list<int> &L, vector<int> & V){
  7.     list<int> :: iterator pos;
  8.  
  9.     //dinamicki alocirati  cu jedno privremeno polje
  10.     // u koje cu smjestiti clanove
  11.     int n =L.size();
  12.     int * A= new int[n];
  13.  
  14.     // kopiram listu u polje
  15.     int i =0;
  16.         for(pos=L.begin();pos!=L.end();++pos){
  17.             A[i] =*pos;
  18.             i++;
  19.         }
  20.         int t, j,imin;
  21.         for(i=0; i<(n-1);i++){
  22.             imin=i;
  23.             for(j=(i+1);j<n;j++)
  24.             if(A[j]<A[imin]){
  25.                 imin=j;
  26.             }
  27.              t=A [i];
  28.             A[i]=A[imin];
  29.             A[imin]=t;
  30.  
  31.  
  32.  
  33.         }
  34.         for(int i=0; i<n;i++){
  35.                 if(A[i]%2==0)
  36.             V.push_back(A[i]);
  37.  
  38.         }
  39.          for(int i=0; i<n;i++){
  40.                 if(A[i]%2!=0)
  41.             V.push_back(A[i]);
  42.  
  43.         }
  44.  
  45. }
  46.  
  47. int main(){
  48.  
  49.     vector<int>v;
  50.     list<int>lista{3,32,32,3,2,4,522,13,1};
  51.     SortListToVector(lista,v);
  52.     for(int i=0; i<v.size();i++)
  53.         cout << v[i] << " ";
  54.  
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement