Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- class FunctorIncrease
- {
- public:
- template <typename T>
- bool operator()(T a, T b)
- {
- if(a>b)
- return true;
- else
- return false;
- }
- };
- template <typename T, typename F = FunctorIncrease>
- void Bubble(T *begin, T *end, F f)
- {
- for(T *i = begin; i!=end-1;i++)
- {
- for(T *j = begin; j!= end-1; j++)
- {
- if(f(*j,*(j+1))==true)
- {
- T temp = *j;
- *j = *(j+1);
- *(j+1) = temp;
- }
- }
- }
- }
- int main()
- {
- int a[10];
- FunctorIncrease f1;
- srand(time(0));
- for(int i = 0;i < 10;i++)
- {
- a[i] = rand()%10+1;;
- }
- Bubble(a,a+10);
- for(int i = 0;i < 10;i++)
- {
- std::cout << a[i] << " ";
- }
- std:: cout << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement