- // another quite typical sorting algorithm implementated in this function,
- // you know it
- void Datastructure::quickSort(std::vector<Person>& A, unsigned int p,
- unsigned int q)
- unsigned int r;
- if(p < q)
- r = partition(A, p,q);
- unsigned int Datastructure::partition(std::vector<Person>& A,
- unsigned int p, unsigned int q)
- // i integeter can be randomized, but trying to did it made me tweaking.
- // I got problem with two mixed conditions, randomizing i wasnt trivial
- unsigned int i = p;
- unsigned int j;
- // at()-functions decreases ~3 percentages 84 % -> 81 %, but safer.
- // enlistingYear is the primary to sort, when it is have a same value
- // then birthYear matters, can be called as older person, when he(or she?)
- // has born earlier (smaller value in birthYear).
- for(j=p+1; j<q; j++)
- if(A.at(j).enlistingYear > A.at(p).enlistingYear ||
- (A.at(j).birthYear >= A.at(p).birthYear && A.at(j).enlistingYear ==
- return i;
- void Datastructure::swap(Person *x, Person *y)
- // Person structure, using pointing Person and referensing temp to y
- // made the program and me crazy
- temp = *x;
- *x = *y;
- *y = temp;
Tuppu Feb 20th, 2015 205 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
RAW Paste Data