Unified
Split
Showing
with
13 additions
and 20 deletions.
- +7 −14 source/Shuffle.cpp
- +3 −4 source/Shuffle.h
- +3 −2 source/Tipster.h
| @@ -5,31 +5,24 @@ | ||
| #include "Shuffle.h" | ||
|
|
||
|
|
||
| void | ||
| Swap(int* a, int* b) | ||
| { | ||
| int temp = *a; | ||
| *a = *b; | ||
| *b = temp; | ||
| } | ||
|
|
||
| // don't use random_shuffle deprecated in the future... | ||
|
|
||
| void | ||
| Randomize(int* arr, int n) | ||
| Randomize(std::vector<int> &arr) | ||
| { | ||
| srand ( time(NULL) ); | ||
|
|
||
| for(int i = n - 1; i > 0; i--) { | ||
| for(int i = arr.size() - 1; i > 0; i--) { | ||
| int j = rand() % (i+1); | ||
| Swap(&arr[i], &arr[j]); | ||
| std::swap(arr[i], arr[j]); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| void | ||
| CreateRandomSeq(int* arr, int len) | ||
| CreateRandomSeq(std::vector<int> &arr, int len) | ||
| { | ||
| for(int i = 0; i < len; ++i) | ||
| arr[i] = i; | ||
| Randomize(arr, len); | ||
| arr.push_back(i); | ||
| Randomize(arr); | ||
| } | ||
| @@ -8,11 +8,10 @@ | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <time.h> | ||
| #include <vector> | ||
|
|
||
|
|
||
| void Swap(int* a, int* b); | ||
| void Randomize(int* arr, int n); | ||
| void CreateRandomSeq(int* arr, int len); | ||
| void Randomize(std::vector<int> &arr); | ||
| void CreateRandomSeq(std::vector<int> &arr, int len); | ||
|
|
||
| #endif | ||
|
|
||
| @@ -15,6 +15,7 @@ | ||
| #include <StringList.h> | ||
| #include <TextView.h> | ||
|
|
||
| #include <vector> | ||
|
|
||
| class Tipster : public BGroupView | ||
| { | ||
| @@ -55,8 +56,8 @@ class Tipster : public BGroupView | ||
| BStringList fTipsList; | ||
| int32 fTipsLength; | ||
| int32 fTipIndex; | ||
| int fRandomSeq1[50]; | ||
| int fRandomSeq2[50]; | ||
| std::vector<int> fRandomSeq1; | ||
| std::vector<int> fRandomSeq2; | ||
|
|
||
| BString* fPreviousTip; | ||
| BString* fCurrentTip; | ||