TypeIIRMLQuicksort.cpp
Go to the documentation of this file.
1 // ---------------------- Doxygen info ----------------------
39 // ----------------------------------------------------------
40 // For a convenient reading of this file's source code,
41 // please use a tab width of four characters.
42 // ----------------------------------------------------------
43 
44 
45 #include <TypeIIRMLQuicksort.h>
46 
47 
48 //************************************************************************************
49 // Quicksort()
50 
51 
52 void TypeIIRMLMath::Quicksort( const int &LeftBound
53  , const int &RightBound
54  , double *ArrayOfValues)
55 {
56  int FirstLoopVariable
57  , SecondLoopVariable;
58 
59  double CurrentValue
60  , HelpVariable;
61 
62  CurrentValue = ArrayOfValues[(LeftBound + RightBound) / 2] ;
63  FirstLoopVariable = LeftBound ;
64  SecondLoopVariable = RightBound ;
65 
66  // try to interexchange elements from the left and from the right
67  while ( FirstLoopVariable <= SecondLoopVariable )
68  {
69  while( ArrayOfValues[FirstLoopVariable] < CurrentValue )
70  {
71  FirstLoopVariable = FirstLoopVariable + 1;
72  }
73 
74  while ( ArrayOfValues[SecondLoopVariable] > CurrentValue )
75  {
76  SecondLoopVariable = SecondLoopVariable - 1;
77  }
78 
79  if ( FirstLoopVariable <= SecondLoopVariable )
80  {
81  // Interexchange ArrayOfValues[i] and ArrayOfValues[j]
82  HelpVariable = ArrayOfValues[FirstLoopVariable] ;
83  ArrayOfValues[FirstLoopVariable] = ArrayOfValues[SecondLoopVariable] ;
84  ArrayOfValues[SecondLoopVariable] = HelpVariable ;
85  FirstLoopVariable = FirstLoopVariable + 1 ;
86  SecondLoopVariable = SecondLoopVariable - 1 ;
87  }
88  }
89 
90  // Recursive call for both subsections
91  if ( LeftBound < SecondLoopVariable )
92  {
93  Quicksort( LeftBound
94  , SecondLoopVariable
95  , ArrayOfValues );
96  }
97 
98  if ( FirstLoopVariable < RightBound )
99  {
100  Quicksort( FirstLoopVariable
101  , RightBound
102  , ArrayOfValues );
103  }
104 }
105 
Header file for the Quicksort algorithm.
void Quicksort(const int &LeftBound, const int &RightBound, double *ArrayOfValues)
Standard implementation of the Quicksort algorithm for double values.


libreflexxestype2
Author(s):
autogenerated on Sat Nov 21 2020 03:17:34