Guest User

Untitled

a guest
Jun 24th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include<iostream>
  2. #include<stdlib.h>
  3. #include<time.h>
  4. using namespace std;
  5.  
  6.  
  7. void bubblesort( float the_array[], int arraySize)
  8. {
  9.     for(int x=0; x<arraySize-1; x++) //sorting algorithm here
  10.      
  11.                         {
  12.                 for(int y=0; y<arraySize-1; y++) //sorting algorithm here
  13.      
  14.                         {
  15.      
  16.                                 if(the_array[y]>the_array[y+1])
  17.      
  18.                                 {
  19.      
  20.                                         float temp = the_array[y+1];
  21.      
  22.                                         the_array[y+1] = the_array[y];
  23.      
  24.                                         the_array[y] = temp;
  25.      
  26.                                 }
  27.      
  28.                         }
  29.       }
  30. }
  31.  
  32. void printArray( float the_array[], int arraySize)
  33. {
  34.     cout << " \n {  ";
  35.         for (int i = 0; i < arraySize; i ++)
  36.         {
  37.             if( i == arraySize - 1)
  38.                 cout << the_array[i];
  39.             else cout << the_array[i] << ", " ;
  40.        
  41.         }
  42.         cout << " } "; 
  43. }
  44.  
  45. int main()
  46. {
  47.         int z = 0;
  48.         int o = 1;
  49.         float infinity = o /( o-o);
  50.         float minus_infinity = -1 * infinity;
  51.         float nan = (o-1)/(o-1);
  52.         float minus_zero = -1*z;
  53.        
  54.         srand(time(NULL));
  55.         float *emptyList = NULL;
  56.         float oneList [] = {3.147678};
  57.         float twoList[] = {34.164, 12.1};
  58.         float longList[] = {1.32, 3.35, 4.97, 4.3215, 3.6457, 3.2798, 1.2457, 3.727678, 3.43457975, 0.124375, 6.3412478, 2.1219788}; // 12 elements
  59.         float sameList[] = { 1.45, 1.58, 1.98 , 1.75, 1.97, 1.75, 1.69, 1.47, 1.45, 2.47, 1.32};
  60.                 //need to do arrays for +- inf, -0 and NaN
  61.         float *randList = new float[150];
  62.         for (int i = 0; i < 150; i ++)
  63.         {
  64.             randList[i] = pow((double)-1,(double)((rand()%2)+1))*((float)(rand()%1000000)/5353);
  65.         }
  66.         *int startTime = clock();
  67.         bubblesort(oneList, 1); // example. will do this for each of the arrays itself.
  68.         int endTime = clock() - startTime;
  69.         printArray(oneList,1);
  70.            cout << endTime;
  71.  
  72.            
  73.         return 0;
  74. }
Add Comment
Please, Sign In to add comment