Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4Sort.hh File Reference
#include "globals.hh"

Go to the source code of this file.

Functions

void sort_double (G4double[], G4int, G4int)
 
void swap_double (G4double[], G4int, G4int)
 

Function Documentation

◆ sort_double()

void sort_double ( G4double  v[],
G4int  left,
G4int  right 
)

Definition at line 39 of file G4Sort.cc.

40{
41 // G4Sort elements in array from v[left] to v[right]
42 // used recursively
43 // algorithm comes from Kernighan and Ritchie, "The C Programming
44 // Language", second edition, p.87
45
46 G4int i, last;
47 if ( left >= right ) // do nothing if array contains
48 return; // fewer than two elements
49
50 swap_double( v, left, ( left + right ) / 2 ); // move part. elt.
51 last = left; // to v[0]
52
53 for ( i = left+1; i <= right; i++ ) // partition
54 if ( v[i] < v[left] )
55 swap_double( v, ++last, i );
56
57 swap_double( v, left, last ); // restore partition element
58
59 sort_double( v, left, last-1 );
60 sort_double( v, last+1, right );
61 return;
62}
void sort_double(G4double v[], G4int left, G4int right)
Definition: G4Sort.cc:39
void swap_double(G4double v[], G4int i, G4int j)
Definition: G4Sort.cc:65
int G4int
Definition: G4Types.hh:66

Referenced by G4ConicalSurface::Intersect(), G4CylindricalSurface::Intersect(), and sort_double().

◆ swap_double()

void swap_double ( G4double  v[],
G4int  i,
G4int  j 
)

Definition at line 65 of file G4Sort.cc.

66{
67 /* interchange elements i and j in an array */
68 G4double temp;
69 temp = v[i];
70 v[i] = v[j];
71 v[j] = temp;
72}
double G4double
Definition: G4Types.hh:64

Referenced by sort_double().