Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int findNear(int value, std::stack<int> stack)
- {
- while(!stack.empty())
- {
- if(stack.top() > value)
- return stack.top();
- else
- stack.pop();
- }
- return -1;
- }
- using namespace std;
- int main() {
- stack<int> source;
- stack<int> used;
- int top;
- for(int i = 0; i < 50000; i++)
- {
- source.push(rand() % 500);
- }
- stack<pair<int, int>> pairs;
- while(!source.empty())
- {
- top = source.top();
- pairs.push(make_pair(top, findNear(top, used)));
- used.push(top);
- source.pop();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement