Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template <class T>
- void bubbleSort(T a[], int n){
- for(int i=0; i < n-1; i++)
- for(int j = n-1; i < j; j--){
- if(a[j] < a[j-1])
- swap(a[j], a[j-1]);
- }
- }
- class myClass{
- public:
- int ID;
- string name;
- ///Overload > and < Operators, using ID as comparing attribute
- bool operator>(const myClass& b){
- return this->ID > b.ID;
- }
- bool operator<(const myClass& b){
- return this->ID < b.ID;
- }
- };
- int main()
- {
- myClass obj[3] = {3, "Victor", 1, "Paul", 2, "Vincent"};
- bubbleSort(obj, 3);
- cout<<"Sorted Array: ";
- for(int i=0; i<3; i++){
- cout<<obj[i].ID<<" "<<obj[i].name;
- i != 2 ? cout<<" -> " : cout<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement