Documente Academic
Documente Profesional
Documente Cultură
H
#ifndef NUMBER_H
#define NUMBER_H
const int SIZE = 6;
template<class T>
class Number{
private:
T num[SIZE];
public:
Number(T[]);
~Number();
void bubbleSort();
void display();
};
#endif
SOURCE.CPP
#include "Header.h"
#include <iostream>
using namespace std;
template<class T>
Number<T>::Number(T array[6]){
for (int i = 0; i < SIZE; i++)
num[i] = array[i];
}
template<class T>
Number<T>::~Number(){}
template<class T>
void Number<T>::bubbleSort(){
bool swap = 1;
T temp;
for (int j = 1; j < SIZE && swap; j++)
{
cout << "Pass " << j << endl;
swap = 0;
for (int k = 0; k < (SIZE - 1); k++)
{
if (num[k]>num[k + 1])
{
temp = num[k];
num[k] = num[k + 1];
num[k + 1] = temp;
swap = 1;
}
display();
cout << endl;
}
cout << endl;
}
}
template<class T>
void Number<T>::display(){
2
45.1 8.1
8.1 45.1
8.1 32.1
8.1 32.1
8.1 32.1
32.1
32.1
45.1
45.1
45.1
56.1
56.1
56.1
56.1
56.1
78.1
78.1
78.1
78.1
78.1
Pass 3
8.1 23.1
8.1 23.1
8.1 23.1
8.1 23.1
8.1 23.1
32.1
32.1
32.1
32.1
32.1
45.1
45.1
45.1
45.1
45.1
56.1
56.1
56.1
56.1
56.1
78.1
78.1
78.1
78.1
78.1
Pass 4
8.1 23.1
8.1 23.1
8.1 23.1
8.1 23.1
8.1 23.1
32.1
32.1
32.1
32.1
32.1
45.1
45.1
45.1
45.1
45.1
56.1
56.1
56.1
56.1
56.1
78.1
78.1
78.1
78.1
78.1
The sorted list is: 8.1 23.1 32.1 45.1 56.1 78.1 Press any key to continue . . .