Created
June 11, 2014 19:57
-
-
Save Qub3k/68f30e946f65b59ea0bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#define SIZE 5 | |
using namespace std; | |
int compare (const void* a, const void* b) // funkcja potrzebna do qsort(), porównuje dwa kolejne elementy | |
{ | |
return(*(double*)a > (*(double*)b)); // jesli zwroci wartosc wieksza od 0 to element 'a' ustawiany jest ZA elementem 'b' | |
} // wiec mamy tutaj kolejnosc rosnaca | |
class Real | |
{ | |
public: | |
Real(double value=0){}; // konstruktor | |
~Real(){}; // destruktor | |
const void Add(double number, int index){ dValue[index-1] = number;} // dodawanie liczby | |
const void Sort() { qsort(dValue, SIZE, sizeof(double), compare);} // sortowanie qsortem | |
const void Printf() // wypisywanie zawartosci tablicy | |
{ | |
cout << "{ "; | |
for(int i = 0; i < SIZE; i++) | |
cout << dValue[i] << ' '; | |
cout << "}" << endl; | |
} | |
private: | |
double dValue[SIZE]; | |
}; | |
int main() | |
{ | |
Real realArray; | |
realArray.Add(1.125, 1); | |
realArray.Add(5.135, 2); | |
realArray.Add(3.129, 3); | |
realArray.Add(6.425, 4); | |
realArray.Add(7.156, 5); | |
realArray.Sort(); | |
realArray.Printf(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment