Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. int findNear(int value, std::stack<int> stack)
  2. {
  3. while(!stack.empty())
  4. {
  5. if(stack.top() > value)
  6. return stack.top();
  7. else
  8. stack.pop();
  9. }
  10. return -1;
  11. }
  12.  
  13. using namespace std;
  14. int main() {
  15.  
  16. stack<int> source;
  17. stack<int> used;
  18. int top;
  19.  
  20. for(int i = 0; i < 50000; i++)
  21. {
  22. source.push(rand() % 500);
  23. }
  24.  
  25. stack<pair<int, int>> pairs;
  26. while(!source.empty())
  27. {
  28. top = source.top();
  29. pairs.push(make_pair(top, findNear(top, used)));
  30. used.push(top);
  31. source.pop();
  32. }
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement