Advertisement
sellmmaahh

t7-zad2

Apr 23rd, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <list>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <string>
  5. #include <iostream>
  6.  
  7. template <typename T>
  8. std::list<T> SortirajListu (std::list<T> lista)
  9. {
  10.     auto it(lista.begin());
  11.     for(it=lista.begin(); it!=lista.end(); it++)
  12.     {
  13.         auto it1=it;
  14.  
  15.         for (auto it2=it1; it2!=lista.end(); it2++)
  16.         {
  17.             if (*it1<*it2)
  18.                std:: swap(*it1, *it2);
  19.  
  20.         }
  21.     }
  22.  
  23.     return lista;
  24. }
  25.  
  26. int main()
  27. {
  28.     int n;
  29.     std::cout<<"Unesite broj elemenata liste: ";
  30.     std::cin>>n;
  31.     std::list<int> l1;
  32.     std::cout<<"Unesite elemente liste: ";
  33.     for (int i=0; i<n; i++)
  34.     {
  35.         int temp;
  36.         std::cin>>temp;
  37.         l1.push_back(temp);
  38.     }
  39.     std::list<int> l2(SortirajListu (l1));
  40.     for (int x: l2)
  41.         std::cout<<x;
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement