Advertisement
vkichukova

Untitled

Feb 2nd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. bool inVector(vector<int> arr, const int element)
  2. {
  3. vector<int>::iterator it = find(arr.begin(), arr.end(), element);
  4. if(it != arr.end())
  5. return true;
  6.  
  7. return false;
  8. }
  9.  
  10. template<class T>
  11. void fillTree(vector<T> leaves, CompleteBinTree<T>& tree)
  12. {
  13. int size = leaves.size();
  14. vector<int> usedPositions;
  15. for(int i = 0; i < size; i++)
  16. usedPositions.push_back(-1);
  17.  
  18. int i = 0;
  19. srand(time(NULL));
  20. while(i < leaves.size())
  21. {
  22. int position = rand() % leaves.size();
  23. if(!inVector(usedPositions, position))
  24. {
  25. usedPositions[i] = position;
  26. i++;
  27. tree.addElement(leaves[position]);
  28. }
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement