Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include<list>
- using namespace std;
- void SortListToVector(list<int> &L, vector<int> & V){
- list<int> :: iterator pos;
- //dinamicki alocirati cu jedno privremeno polje
- // u koje cu smjestiti clanove
- int n =L.size();
- int * A= new int[n];
- // kopiram listu u polje
- int i =0;
- for(pos=L.begin();pos!=L.end();++pos){
- A[i] =*pos;
- i++;
- }
- int t, j,imin;
- for(i=0; i<(n-1);i++){
- imin=i;
- for(j=(i+1);j<n;j++)
- if(A[j]<A[imin]){
- imin=j;
- }
- t=A [i];
- A[i]=A[imin];
- A[imin]=t;
- }
- for(int i=0; i<n;i++){
- if(A[i]%2==0)
- V.push_back(A[i]);
- }
- for(int i=0; i<n;i++){
- if(A[i]%2!=0)
- V.push_back(A[i]);
- }
- }
- int main(){
- vector<int>v;
- list<int>lista{3,32,32,3,2,4,522,13,1};
- SortListToVector(lista,v);
- for(int i=0; i<v.size();i++)
- cout << v[i] << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement