Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<cstdlib>
- #include<algorithm>
- #include<ctime>
- #include<cstdlib>
- #include<time.h>
- #include<fstream>
- #include<chrono>
- #define LEWY(w) ((2)*(w))
- #define PRAWY(w) ((w)*2 +1)
- using namespace std;
- int licznik_operacji = 0 ;//porownanie i zamiana
- void losowe_liczby_increase(int n, int *tab, int k);
- bool malejaco(int a, int b);
- void losowe_liczby_decrease(int n, int *tab, int k);
- void losowe_liczby_V(int n, int *tab, int k);
- void losowe_liczby_A(int n, int *tab, int k);
- void losowe_liczby_los(int n, int *tab, int k);
- void Shell_Sort_sh(int *tab, int n)
- {
- int buff, j;
- for (int dys = n / 2; dys > 0; dys /= 2)
- {
- for (int i = dys; i < n; i++)
- {
- buff = tab[i];
- licznik_operacji++;
- for (j = i; j >= dys && tab[j - dys] > buff; j -= dys)
- tab[j] = tab[j - dys];
- licznik_operacji++;
- tab[j] = buff;
- licznik_operacji++;
- }
- }
- }
- void Shell_Sort_kn(int *tab, int n)
- {
- int buff, j;
- for (int dys = n / 3; dys > 0; dys /= 3)
- {
- for (int i = dys; i < n; i++)
- {
- buff = tab[i];
- licznik_operacji++;
- for (j = i; j >= dys && tab[j - dys] > buff; j -= dys)
- tab[j] = tab[j - dys];
- licznik_operacji++;
- tab[j] = buff;
- licznik_operacji++;
- }
- }
- }
- void insertion_sort_najprostszy(int n, int *tab)///////////przez wstawnianie
- {
- int j;
- int pom;
- for (int i = 1; i < n; i++) {
- pom = i;
- j = i - 1;
- while (tab[j] > tab[pom] && j >= 0) { swap(tab[j], tab[pom]); pom--; j--; }
- }
- }
- void scal(int dol, int srodek, int gora, int *tab, int * pom) {
- int i = dol, j = srodek + 1;
- for (int k = dol; k <= gora; k++) { pom[k] = tab[k]; }
- for (int k = dol; k <= gora; k++) {
- if (i <= srodek) {
- licznik_operacji++;
- if (j <= gora) {
- licznik_operacji++;
- if (pom[j] < pom[i]) {
- tab[k] = pom[j++];
- licznik_operacji += 2;
- }
- else
- tab[k] = pom[i++];
- licznik_operacji++;
- }
- else
- tab[k] = pom[i++];
- licznik_operacji++;
- }
- else
- tab[k] = pom[j++];
- licznik_operacji++;
- }
- }
- void Merge_sort(int dol, int gora, int *tab, int * pom) {
- licznik_operacji++;
- if (gora <= dol) return;
- Merge_sort(dol, (dol + gora) / 2, tab, pom);
- Merge_sort((dol + gora) / 2 + 1, gora, tab, pom);
- scal(dol, (gora + dol) / 2, gora, tab, pom);
- }
- void selection_sort(int tab[], const int & n)//przez wybieranie
- {
- int maxi = tab[1];
- for (int j = 0; j < n - 1; j++) {
- maxi = tab[j];
- for (int i = j + 1; i < n; i++) {
- if (tab[i] > maxi) {
- maxi = tab[i];
- tab[i] = tab[j];
- tab[j] = maxi;
- }
- }
- }
- }
- template<typename T, typename Assigment>
- void swap(T& a, T& b, Assigment&& as)
- {
- T c;
- as(c, a);
- as(a, b);
- as(b, c);
- }
- template<typename Lesser, typename Greater, typename Assigment>
- void restore_heap(int n, int *tab, int wezel, Lesser&& lesser, Greater&& greater, Assigment&& assigment) {//n to jest heap size
- int largest;
- int l, p;
- assigment(l, LEWY(wezel));
- assigment(p, PRAWY(wezel));
- if (lesser(l, n) && greater(tab[l], tab[wezel])) //lewy
- {
- assigment(largest, l);
- }
- else
- {
- assigment(largest, wezel);
- }
- if (lesser(p,n) && greater(tab[p] , tab[largest]))
- {
- assigment(largest, p);
- }
- swap(tab[wezel], tab[largest], assigment);
- if (largest != wezel)
- restore_heap(n, tab, largest, lesser, greater, assigment);
- }
- template<typename Lesser, typename Greater, typename Assigment>
- void zbuduj_heap(int n, int *tab, Lesser&& lesser, Greater&& greater, Assigment&& assigment) {
- int i;
- assigment(i, n / 2);
- for (; greater(i, 0); i--)
- {
- restore_heap(n, tab, i, lesser, greater, assigment);
- }
- }
- template<typename Lesser, typename Greater, typename Assigment>
- void heap_sort(int *tab, int n, Lesser&& lesser, Greater&& greater, Assigment&& assigment) {//na potrzeby heap sort nalezy indeksowac od i =1 do n
- zbuduj_heap(n, tab, lesser, greater, assigment);
- assigment(n, n - 1);
- for (int i = n; i > 1; i--) {
- swap(tab[1], tab[i], assigment);
- assigment(n, n - 1);
- restore_heap(n, tab, 1, lesser, greater, assigment);
- }
- }
- void quick_sort(int tab[], int dol, int gora) {//pivotem pierwszy el tablicy
- licznik_operacji++;
- if (gora <= dol) { return; }
- int pivot = tab[dol];
- //cout << pivot << endl;///////////////////////wypisz wartosc pivota w kazdym wywolaniu
- int j = gora + 1, i = dol - 1;
- licznik_operacji+=3;////////////////////////////////////////////////////////////////////////////////// licznik
- while (1) {
- while (pivot > tab[++i]) { licznik_operacji += 2; };
- while (pivot < tab[--j]) { licznik_operacji += 2; };
- licznik_operacji += 3;
- if (j >= i) { swap(tab[i], tab[j]); licznik_operacji ++;
- }
- else { break; }
- }
- licznik_operacji+=2;
- if (j > dol) { quick_sort(tab, dol, j); }
- if (i < gora) { quick_sort(tab, i, gora); }
- }
- template<typename T>
- void sortowanie(T gen, fstream& plik, int* tab, int N = 4000000, int skok = 100000)
- {
- plik << "n;czas;liczba operacji" << endl;
- for (int n = 1; n < N; n += skok) {
- licznik_operacji = 0;
- gen(n, tab, 500000);
- auto start = chrono::steady_clock::now();
- quick_sort(tab, 0, n - 1);
- auto end = chrono::steady_clock::now();
- // Store the time difference between start and end
- auto diff = end - start;
- plik << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- plik << ";;;" << endl;
- }
- struct Assign
- {
- template<typename A, typename B>
- bool operator()(A&& a, B&& b) { return a = b; }
- };
- template<typename Operator>
- struct OperatorCounter
- {
- size_t counter{ 0 };
- template<typename... Args>
- bool operator()(Args&&... args)
- {
- bool rv = Operator()(std::forward<Args>(args)...);
- counter++;
- return rv;
- }
- };
- int main()
- {
- srand((int)time(NULL));
- auto start = chrono::steady_clock::now();
- auto end = chrono::steady_clock::now();
- auto diff = end - start;
- int akcja;
- /*cout << "wielkosc tablicy rand do posortowania";
- int n;
- cin >> n;
- int* tab = new int[n];
- srand((int) time(NULL));
- losowe_liczby_A(n , tab, 50);///////////////po kazdym sortowaniu nalezy wyzerowac zmienna licznik operacji
- cout << endl<<endl;*/
- cout << "co chcesz robic : 1 wczytaj parametry sortowan do plikow; 2 wczytaj dane z klawiatury i zobacz posortowana tablice na konsoli ";
- cin >> akcja;
- switch (akcja) {
- case 1://aktualizowanie danych w plikach
- { cout << "parametry ktorego sortowania chcesz zaktualizowac? 1 qs 2 hs 3 merge sort 4 shell srt shella 5 shell sort knutha";
- cin >> akcja;
- int* tab = new int[4000001];
- for (int i = 0; i < 4; i++)
- {//for na rzecz nie przeklikiwania wszystkiego
- switch (akcja) {
- case 1: //quick sort
- {//quick sort
- fstream quick_A, quick_V, quick_inc, quick_dec, quick_los;
- quick_A.open("quick_A.txt", ios::app | ios::out);
- quick_V.open("quick_V.txt", ios::app | ios::out);
- quick_inc.open("quick_increase.txt", ios::app | ios::out);
- quick_dec.open("quick_decrease.txt", ios::app | ios::out);
- quick_los.open("quick_los.txt", ios::app | ios::out);
- sortowanie(losowe_liczby_A, quick_A, tab);
- break;
- }
- case 2://heap sort do zrobienie przetestowac heap sorta czy dziala
- {
- fstream heap_A, heap_V, heap_inc, heap_dec, heap_los;
- heap_A.open("heap_A.txt", ios::app | ios::out);
- heap_V.open("heap_V.txt", ios::app | ios::out);
- heap_inc.open("heap_increase.txt", ios::app | ios::out);
- heap_dec.open("heap_decrease.txt", ios::app | ios::out);
- heap_los.open("heap_los.txt", ios::app | ios::out);
- int* tab_heap = new int[4000001];//dla heap sorta gdzie tablica musi miec cindeksy 1 ...n
- //losowe_liczby_los(n+1, tab_heap, 50);//zmieniam ta funkcje dla heap sorta gdzie tablica musi miec cindeksy 1 ...n pamietaj o n+1 dla heap sorta przy losowaniu
- tab_heap[0] = NULL;
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- OperatorCounter<Assign> assigment;
- OperatorCounter<less<int>> lesser;
- OperatorCounter<greater<int>> greater;
- losowe_liczby_A(n + 1, tab_heap, 500000);
- start = chrono::steady_clock::now();
- heap_sort(tab_heap, n, lesser, greater, assigment);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- heap_A << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- cout << "Operations count:\nAssigment: " << assigment.counter << "\nLesser: " << lesser.counter << "\nGreater: " << greater.counter << '\n';
- }
- heap_A << ";;;" << endl;
- /////////////////////////////////////////////////////
- /*
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_V(n + 1, tab_heap, 500000);
- start = chrono::steady_clock::now();
- heap_sort(tab_heap, n);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- heap_V << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- heap_V << ";;;" << endl;
- ///////////////////////////////////////////////////
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_los(n + 1, tab_heap, 500000);
- start = chrono::steady_clock::now();
- heap_sort(tab_heap, n);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- heap_los << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- heap_los << ";;;" << endl;
- ////////////////////////////////////////////////////////////////////////////////////
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_increase(n + 1, tab_heap, 500000);
- start = chrono::steady_clock::now();
- heap_sort(tab_heap, n);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- heap_inc << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- heap_inc << ";;;" << endl;
- ///////////////////////////////////////////////////
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_decrease(n + 1, tab_heap, 500000);
- start = chrono::steady_clock::now();
- heap_sort(tab_heap, n);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- heap_dec << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- heap_dec << ";;;" << endl;
- */
- delete[] tab_heap;
- //break;
- }
- case 3://merge sort
- {
- fstream merge_A, merge_V, merge_inc, merge_dec, merge_los;
- merge_A.open("merge_A.txt", ios::app | ios::out);
- merge_V.open("merge_V.txt", ios::app | ios::out);
- merge_inc.open("merge_increase.txt", ios::app | ios::out);
- merge_dec.open("merge_decrease.txt", ios::app | ios::out);
- merge_los.open("merge_los.txt", ios::app | ios::out);
- int* tab = new int[4000000];
- int *pom = new int[4000000];
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_A(n, tab, 500000);
- start = chrono::steady_clock::now();
- Merge_sort(0, n, tab, pom);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- merge_A << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- merge_A << ";;;" << endl;
- //////////////////////////////////////////////////////////////
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_V(n, tab, 500000);
- start = chrono::steady_clock::now();
- Merge_sort(0, n, tab, pom);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- merge_V << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- merge_V << ";;;" << endl;
- ///////////////////////////////////////////////////
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_los(n, tab, 500000);
- start = chrono::steady_clock::now();
- Merge_sort(0, n, tab, pom);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- merge_los << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- merge_los << ";;;" << endl;
- ////////////////////////////////////////////////////////////////////////////////////
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_increase(n, tab, 500000);
- start = chrono::steady_clock::now();
- Merge_sort(0, n, tab, pom);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- merge_inc << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- merge_inc << ";;;" << endl;
- ///////////////////////////////////////////////////
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_decrease(n, tab, 500000);
- start = chrono::steady_clock::now();
- Merge_sort(0, n, tab, pom);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- merge_dec << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- merge_dec << ";;;" << endl;
- delete[] pom;
- //break;
- }
- case 4: //shell_sh z przyrostami shella
- {
- fstream shell_sh_A, shell_sh_V, shell_sh_inc, shell_sh_dec, shell_sh_los, shell_sh;
- shell_sh_A.open("shell_sh_A.txt", ios::app | ios::out);
- shell_sh_V.open("shell_sh_V.txt", ios::app | ios::out);
- shell_sh_inc.open("shell_sh_increase.txt", ios::app | ios::out);
- shell_sh_dec.open("shell_sh_decrease.txt", ios::app | ios::out);
- shell_sh_los.open("shell_sh_los.txt", ios::app | ios::out);
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_A(n, tab, 500000);
- start = chrono::steady_clock::now();
- Shell_Sort_sh(tab, n);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- shell_sh_A << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- shell_sh_A << ";;;" << endl;;
- /////////////////////////////////////////////////////
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_V(n, tab, 500000);
- start = chrono::steady_clock::now();
- Shell_Sort_sh(tab, n);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- shell_sh_V << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- shell_sh_V << ";;;" << endl;;;
- ///////////////////////////////////////////////////
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_increase(n, tab, 500000);
- start = chrono::steady_clock::now();
- Shell_Sort_sh(tab, n);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- shell_sh_inc << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- shell_sh_inc << ";;;" << endl;;;
- ///////////////////////////////////////////////////
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_decrease(n, tab, 500000);
- start = chrono::steady_clock::now();
- Shell_Sort_sh(tab, n);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- shell_sh_dec << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- shell_sh_dec << ";;;" << endl;;
- ///////////////////////////////////////////////////
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_los(n, tab, 500000);
- start = chrono::steady_clock::now();
- Shell_Sort_sh(tab, n);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- shell_sh_los << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- shell_sh_los << ";;;" << endl;;
- //break;
- }
- case 5://z przyrostami knutha
- {
- fstream shell_kn_A, shell_kn_V, shell_kn_inc, shell_kn_dec, shell_kn_los;
- shell_kn_A.open("shell_kn_A.txt", ios::app | ios::out);
- shell_kn_V.open("shell_kn_V.txt", ios::app | ios::out);
- shell_kn_inc.open("shell_kn_increase.txt", ios::app | ios::out);
- shell_kn_dec.open("shell_kn_decrease.txt", ios::app | ios::out);
- shell_kn_los.open("shell_kn_los.txt", ios::app | ios::out);
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_A(n, tab, 500000);
- start = chrono::steady_clock::now();
- Shell_Sort_kn(tab, n);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- shell_kn_A << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- shell_kn_A << ";;;" << endl;
- /////////////////////////////////////////////////////
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_V(n, tab, 500000);
- start = chrono::steady_clock::now();
- Shell_Sort_kn(tab, n);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- shell_kn_V << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- shell_kn_V << ";;;" << endl;
- ///////////////////////////////////////////////////
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_increase(n, tab, 500000);
- start = chrono::steady_clock::now();
- Shell_Sort_kn(tab, n);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- shell_kn_inc << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- shell_kn_inc << ";;;" << endl;
- ///////////////////////////////////////////////////
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_decrease(n, tab, 500000);
- start = chrono::steady_clock::now();
- Shell_Sort_kn(tab, n);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- shell_kn_dec << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- shell_kn_dec << ";;;" << endl;
- ///////////////////////////////////////////////////
- for (int n = 1; n < 4000000; n += 100000) {
- licznik_operacji = 0;
- losowe_liczby_los(n, tab, 500000);
- start = chrono::steady_clock::now();
- Shell_Sort_kn(tab, n);
- end = chrono::steady_clock::now();
- // Store the time difference between start and end
- diff = end - start;
- shell_kn_los << n << ";" << chrono::duration <double, milli>(diff).count() << "" << ";" << licznik_operacji << endl;
- }
- shell_kn_los << ";;;" << endl;
- break;
- }
- default: {system("pause");
- delete[] tab;
- return 0; }
- }
- }
- delete[] tab;
- return 0;
- }
- case 2://pisanie z klawiatury
- {
- cout << "najpierw podaj dlugosc tablicy do posortowania";
- int n;
- cin >> n;
- int* tab = new int[n];
- for (int i = 0; i < n; i++) {
- cout << "podawaj liczby dopoki petla sie nie skonczy";
- cin >> tab[i];
- }
- cout << "ktorego sortowania dane chcesz podac z klawiatury?: 1 qs 2 hs 3 merge sort 4 shell srt shella 5 shell sort knutha cokolwiek innego zeby przerwac";
- cin >> akcja;
- switch (akcja) {
- case 1: {
- quick_sort(tab,0,n-1);
- for (int i = 0; i < n;i++) {
- cout << tab[i] << ", ";
- }
- break;
- }
- case 2: {
- int* tab2 = new int[n + 1];
- tab2[0] = NULL;
- for (int i = 1; i < n + 1;i++) {
- tab2[i] = tab[i - 1];
- }
- //heap_sort(tab2,n+1);
- for (int i = 0; i < n; i++) {
- cout << tab2[i] << ", ";
- }
- delete[] tab2 ;
- break;
- }
- case 3: {
- int * pom = new int[n];
- Merge_sort(0,n-1,tab,pom);
- for (int i = 0; i < n; i++) {
- cout << tab[i] << ", ";
- }
- delete [] pom;
- break;
- }
- case 4: {
- Shell_Sort_sh(tab,n);
- for (int i = 0; i < n; i++) {
- cout << tab[i] << ", ";
- }
- break;
- }
- case 5: {
- Shell_Sort_kn(tab,n);
- for (int i = 0; i < n; i++) {
- cout << tab[i] << ", ";
- }
- break;
- }
- }
- delete[] tab;
- break;
- }
- default: {return 0; }
- break;
- }
- //shell_sort_sh(n,tab);
- //insertion_sort_najprostszy(n,tab);
- //quick_sort(tab, 0, n - 1);
- //selection_sort(tab ,n);
- //shell_sort_kn(n,tab);
- ///////////////////////merge sort
- /*int *pom = new int[n];//na potrzeby merge sorta pomocnicza struktura danych
- Merge_sort(0,n-1,tab,pom);
- delete[] pom;*/
- system("pause");
- cout << "koniec";
- return 0;
- }
- void losowe_liczby_decrease(int n, int *tab, int k) {
- losowe_liczby_los(n, tab, k);
- sort(tab, tab + n - 1, malejaco);
- /*for (int i = 0; i < n; i++)
- {
- printf("%d, ", tab[i]);
- }
- cout << endl;
- */
- }
- bool malejaco(int a, int b) {
- return (a > b);
- }
- void losowe_liczby_increase(int n, int *tab, int k) {
- losowe_liczby_los(n, tab, k);
- sort(tab, tab + n - 1);
- /*for (int i = 0; i < n; i++)
- {
- printf("%d, ", tab[i]);
- }
- cout << endl;
- */
- }
- void losowe_liczby_V(int n, int *tab, int k) {
- losowe_liczby_los(n, tab, k);
- sort(tab + n / 2, tab + n);
- sort(tab, tab + n / 2, malejaco);
- /*for (int i = 0; i < n; i++)
- {
- printf("%d, ", tab[i]);
- }
- cout << endl;
- */
- }
- void losowe_liczby_A(int n, int *tab, int k) {
- losowe_liczby_los(n, tab, k);
- sort(tab + n / 2, tab + n, malejaco);
- sort(tab, tab + n / 2);
- /*for (int i = 0; i < n; i++)
- {
- printf("%d, ", tab[i]);
- }
- cout << endl;
- */
- }
- void losowe_liczby_los(int n, int *tab, int k) {
- for (int i = 0; i <n; i++)
- {
- tab[i] = ((int)rand() % (k - 10)) + 10;
- }
- /*for (int i = 0; i < n; i++)
- {
- printf("%d, ", tab[i]);
- }
- cout << endl;
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement