Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <class T>
  6. void bubbleSort(T a[], int n){
  7. for(int i=0; i < n-1; i++)
  8. for(int j = n-1; i < j; j--){
  9. if(a[j] < a[j-1])
  10. swap(a[j], a[j-1]);
  11. }
  12. }
  13.  
  14. class myClass{
  15. public:
  16. int ID;
  17. string name;
  18.  
  19. ///Overload > and < Operators, using ID as comparing attribute
  20. bool operator>(const myClass& b){
  21. return this->ID > b.ID;
  22. }
  23. bool operator<(const myClass& b){
  24. return this->ID < b.ID;
  25. }
  26. };
  27.  
  28. int main()
  29. {
  30. myClass obj[3] = {3, "Victor", 1, "Paul", 2, "Vincent"};
  31.  
  32. bubbleSort(obj, 3);
  33.  
  34. cout<<"Sorted Array: ";
  35. for(int i=0; i<3; i++){
  36. cout<<obj[i].ID<<" "<<obj[i].name;
  37. i != 2 ? cout<<" -> " : cout<<endl;
  38. }
  39.  
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement