Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <ctime>
- #include <cstdlib>
- #include <functional>
- #include <string>
- #include <array>
- #include "Timer.cpp"
- #include <windows.h>
- #include <vector>
- #include <cstdio>
- #include <clocale>
- #include <fstream>
- using namespace std;
- void bubble_s( unsigned short* tab, int size_a )
- {
- for( int i = 0; i < size_a; i++ )
- {
- for( int j = 0; j < size_a - 1; j++ )
- {
- if( tab[ j ] > tab[ j + 1 ] ) {
- swap( tab[ j ], tab[ j + 1 ] );
- }
- }
- }
- }
- void q_sort( unsigned short* tab, int left, int right )
- {
- int i = left;
- int j = right;
- int x = tab[( left + right ) / 2 ];
- do
- {
- while( tab[ i ] < x )
- i++;
- while( tab[ j ] > x )
- j--;
- if( i <= j )
- {
- swap( tab[ i ], tab[ j ] );
- i++;
- j--;
- }
- } while( i <= j );
- if( left < j ) q_sort( tab, left, j );
- if( right > i ) q_sort( tab, i, right );
- }
- void i_sort( unsigned short* tab, int size_a )
- {
- int temp, j;
- for( int i = 1; i < size_a; i++ )
- {
- temp = tab[ i ];
- for( j = i - 1; j >= 0 && tab[ j ] > temp; j-- )
- tab[ j + 1 ] = tab[ j ];
- tab[ j + 1 ] = temp;
- }
- }
- int * arr_c(int b)
- {
- int * t = new int [b];
- for(int f = 0; f < b; f++)
- {
- t[f] = rand();
- }
- return t;
- }
- void ins_arr( unsigned short* arr, int size_a ) {
- for(int c=0; c<size_a; c++) {
- arr[c] = rand()%101/*65535*/;
- }
- }
- void paste_data (unsigned short* arr1, unsigned short* arrconst, int size_a ) {
- for(int c=0; c<size_a; c++) {
- arr1[c] = arrconst[c];
- }
- }
- struct node
- {
- int data;
- node *next;
- };
- int main() {
- srand(time(NULL));
- int * W = arr_c(5);
- const int val[4] = { 1E4, 2E4, 3E4, 4E4 };/*1E6, 1E7, 1E8, 5E8*/
- const string nam[4] = { "Bubble", "Quick", "Insert", "Sort" };
- /*
- unsigned short** arr0 = new unsigned short* [4];
- for( int a=0; a<4; a++ ) {
- arr0[a] = new unsigned short [val[a]];
- ins_arr(arr0[a], val[a]);
- }*/
- time_t czas = 0;
- time( & czas );
- string nazwa = "stats.txt";
- fstream plik;
- plik.open( nazwa , ios::out );
- plik << endl << ctime( & czas );
- cout << endl << ctime( & czas );
- unsigned short* arrconst = new unsigned short [val[3]];
- ins_arr(arrconst,val[3]);
- for(int c=0; c<4; c++) {
- cout << endl << nam[c] <<":" << endl;
- plik << endl << nam[c] <<":" << endl;
- for(int b=0; b<4; b++) {
- cout << endl << "Tab" << b+1 << "["<< val[b] <<"]:" << endl;
- plik << endl << "Tab" << b+1 << "["<< val[b] <<"]:" << endl;
- unsigned short* arr0 = new unsigned short [val[b]];
- paste_data(arr0,arrconst, val[b]);
- Timer timer;
- timer.start_counter();
- cout << arr0[0]<< " | " << arr0[1]<< " | " << arr0[2]<< " | " << arr0[3] << endl;
- switch( c ) {
- case 0:
- bubble_s(arr0, val[b]);
- break;
- case 1:
- q_sort(arr0, 0, val[b]);
- break;
- case 2:
- i_sort(arr0, val[b]);
- break;
- case 3:
- sort(arr0, arr0 + val[b]);
- break;
- }
- cout << arr0[0]<< " | " << arr0[1]<< " | " << arr0[2]<< " | " << arr0[3] << endl;
- timer.stop_counter();
- delete arr0;
- cout <<timer.get_elapsed_time()<< endl;
- plik <<timer.get_elapsed_time()<< endl;
- }
- }
- plik.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement