#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
template<typename ElementType>
void SortBubble(ElementType* a, int size)
{
int i, work;
ElementType temp;
for (int j = 1; j < size; j++)
{
work = 1;
for (i = 0; i < size - j; i++)
if (a[i] < a[i + 1])
{
temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
work = 0;
}
if (work) break;
}
};
class Box
{
private:
int c, k, g;
public:
Box(int cc=0, int kk=0, int gg=0)
{
c = cc; k = kk; g = gg;
}
void Show(){cout << c << "-" << k << "-" << g <<"="<<c*k*g << endl; }
friend bool operator<(Box& b1, Box& b2)
{
if (b1.c * b1.g * b1.k < b2.c * b2.g * b2.k)
return true;
else
return false;
}
};
// void SortBubble(int* array, int size);
// void SortBubble(Box* boxes, int size);
int main()
{
int *a =new int[10]{1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
void SortBubble(int* array, int size);
SortBubble(a, 10);
for (int i = 0; i < 10; i++)
cout << a[i] << " ";
cout << endl;
void SortBubble(Box * boxes, int size);
Box* b = new Box[4]{Box(2,2,2),Box(1,1,1),Box(3,3,3),Box(9,9,9)};
SortBubble(b, 4);
for (int i = 0; i < 4; i++)
b[i].Show();
return 0;
}
|