Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef SORT_BY_H
- #define SORT_BY_H
- #include <algorithm>
- #include "Company.h"
- void sortBy(Company** frontPtrs, Company** endPtrs, bool(&lessThan)(const Company& a, const Company& b))
- {
- Company* temp;
- bool flag;
- int size = endPtrs - frontPtrs;
- for(int i = 0; i < size - 1; i++)
- {
- flag = false;
- for (int j = 0; j < size - i - 1; j++)
- {
- if (!lessThan(*frontPtrs[j], *frontPtrs[j + 1]))
- {
- temp = frontPtrs[j];
- frontPtrs[j] = frontPtrs[j + 1];
- frontPtrs[j + 1] = temp;
- flag = true;
- }
- }
- if (!flag)
- break;
- }
- }
- #endif // !SORT_BY_H
Advertisement
Add Comment
Please, Sign In to add comment