# Sorting of big arrays

Email
 Submitted on: 1/2/2015 10:10:00 AM By: Parz Alexander (from psc cd) Level: Beginner User Rating: By 2 Users Compatibility: C, C++ (general) Views: 570

You can test 7 different sorting algorithms, with random numbers even large numbers not only integers.

code:
Can't Copy and Paste this?
 ``` //************************************** // Name: Sorting of big arrays // Description:You can test 7 different sorting algorithms, with random numbers even large numbers not only integers. // By: Parz Alexander (from psc cd) // // Inputs:1.)Which sorting algorithm. 2.)Starting number of the random number 3.)Ending number of the random number 4.)Amount of the random numbers // // Returns:1.)You can choose if you want to see the unsorted and sorted array. 2.)The sec. how long the choosen sorting algorithm needs. // // Assumes:My aim had been to produce random numbers larger than 32767 in a range which you can choose. //************************************** /*Alexander You can choose any starting and ending point also you can choose the amount of numbers to be sorted. I tried to play with Prototypes so I wrote this prg. It should be easy to understand and you can take out very easy any sorting algorithm for your own purpose. If you find some bugs please tell me. I just started to learn C++ 2 months ago so it is possible that there are some bugs.*/ #include #include #include #include #include #include #include long Zufallszahlen(long,long); void UAusgabe(long *, long); void SAusgabe(long *, long); void Bubblesort (long *, long); void DoubleBubble (long *, long); void Selectionsort (long *, long); void Insertionsort (long *,long); void Shellsort (long *, long); void Heapsort(long *, long); void BuildHeap(long, long *, long); void Quicksort(long *, long); void QuickLR(long *, long, long); double tBubble(0); double tDouble(0); double tInsertion(0); double tSelection(0); double tShell(0); double tQuick(0); double tHeap(0); void main() { long a(0); long b(0); long c(0); long d(0); int e(0); int e1[8]={0,0,0,0,0,0,0,0}; int e2(-1); int f(0); long i(0); time_t m; time(&m); srand(m); do { cout << "Choose the Sorting Algorithm???" << endl << endl << "1.) Bubblesort" << endl << "2.) Doublesort" << endl << "3.) Selectionsort" << endl << "4.) Insertionsort" << endl << "5.) Shellsort" << endl << "6.) Heapsort" << endl << "7.) Quicksort " << endl << "8.) All" << endl << "9.) Choosen" << endl << endl << "Type in the number" << endl; cin >> e; e2++; e1[e2]=e; } while((e!=9) && (e!=8)); cout << "Type in the start number" << endl; cin >> a; cout << endl; cout << "Type in the end number" << endl; cin >> b; cout << endl; cout << "How many random numbers???" << endl; cin >> c; cout << endl; cout << "Want to print out the numbers" << endl << "Press 1 for YES 0 for NO" << endl; cin >> f; cout << endl; long *x = new long[c]; long *y = new long[c]; for(d=0;dx[b+1]) { x[b]^=x[b+1]; x[b+1]^=x[b]; x[b]^=x[b+1]; } } } t2=clock(); tBubble = (double)(t2-t1)/CLOCKS_PER_SEC; } void DoubleBubble(long *x,long c) { long a(0); long b(0); long i(0); long j(1); double t1(0); double t2(0); t1=clock(); a=c-1; b=-1; while(bx[i+1]) { x[i]^=x[i+1]; x[i+1]^=x[i]; x[i]^=x[i+1]; } for(j=a;j>=b;--j) if (x[j]>x[j+1]) { x[j]^=x[j+1]; x[j+1]^=x[j]; x[j]^=x[j+1]; } } t2=clock(); tDouble = (double)(t2-t1)/CLOCKS_PER_SEC; } void Selectionsort(long *x,long c) { long a(0); long b(0); long d(0); long m(0); double t1(0); double t2(0); t1=clock(); for(a=0;a d);b--) { x[b]=x[b-1]; } x[b]=d; } t2=clock(); tInsertion = (double)(t2-t1)/CLOCKS_PER_SEC; } void Shellsort(long *x,long c) { long a(0); long b(0); long d(0); long h(0); long i(0); double t1(0); double t2(0); cout << endl; cout << "Please type in an int number for the row of Shellsort" << endl; cin >> i; t1=clock(); for(h=1;h<=c/(i*i);h=i*h+1) ; for (; h>0;h/=i) { for(a=h;a=h) && (x[b-h] > d);b-=h) { x[b]=x[b-h]; } x[b]=d; } } t2=clock(); tShell = (double)(t2-t1)/CLOCKS_PER_SEC; } void Heapsort(long *x, long c) { long k(0); long t(0); double t1(0); double t2(0); t1=clock(); for(k=c/2;k;) { BuildHeap(c,x,--k); } while( --c) { x[c]^=x[0]; x[0]^=x[c]; x[c]^=x[0]; BuildHeap(c, x, 0); } t2=clock(); tHeap = (double)(t2-t1)/CLOCKS_PER_SEC; } void BuildHeap(long c, long *x, long k) { long i(0); long j(0); j=x[k]; while(k=x[i]) break; x[k]=x[i]; k=i; } x[k]=j; } void Quicksort(long *x, long c) { double t1(0); double t2(0); t1=clock(); QuickLR(x,c-1,0); t2=clock(); tQuick = (double)(t2-t1)/CLOCKS_PER_SEC; } void QuickLR( long *x,long r,long l) { long med(0); long i(0); long j(0); if(r>l) { med=x[r]; i=l-1; j=r; for(;;) { while(x[++i]med) ; if(i>=j) break; x[i]^=x[j]; x[j]^=x[i]; x[i]^=x[j]; } x[r]=x[i]; x[i]=med; QuickLR(x,i-1,l); QuickLR(x,r,i+1); } } void UAusgabe(long *y ,long c) { long z(0); for(z=0;z

Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)