Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <list>
- #include <iostream>
- #include <chrono>
- #include <ctime>
- template <class InIt>
- void bubblesort(InIt start, InIt stop)
- {
- InIt k = stop, j_1;
- for (auto i = start; i != stop; ++i)
- {
- for (auto j = std::next(start, 1); j != k; ++j)
- {
- j_1 = std::prev(j, 1);
- if (*j_1 > *j)
- {
- auto temp = *j;
- *j = *j_1;
- *j_1 = temp;
- //std::swap(*j,*j_1);
- }
- }
- --k;
- }
- }
- int main()
- {
- std::list<int> l;
- for (int i = 0; i != 10000; ++i)
- l.push_front(i);
- //for (auto i : l) std::cout << i << ' '; std::cout << std::endl;
- std::chrono::time_point<std::chrono::system_clock> start, end;
- start = std::chrono::system_clock::now();
- bubblesort(l.begin(), l.end());
- end = std::chrono::system_clock::now();
- std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count() / 1000.0
- << " sec" << std::endl;
- //for (auto i : l) std::cout << i << ' '; std::cout << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement