Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool inVector(vector<int> arr, const int element)
- {
- vector<int>::iterator it = find(arr.begin(), arr.end(), element);
- if(it != arr.end())
- return true;
- return false;
- }
- template<class T>
- void fillTree(vector<T> leaves, CompleteBinTree<T>& tree)
- {
- int size = leaves.size();
- vector<int> usedPositions;
- for(int i = 0; i < size; i++)
- usedPositions.push_back(-1);
- int i = 0;
- srand(time(NULL));
- while(i < leaves.size())
- {
- int position = rand() % leaves.size();
- if(!inVector(usedPositions, position))
- {
- usedPositions[i] = position;
- i++;
- tree.addElement(leaves[position]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement