Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

chari407's blog

By chari407, history, 9 years ago, In English

Hi, I have a couple of doubts. 1. Can we use the standard C++ binary_search() on a stack<> ? 2. Suppose I declare

struct sig
{
int a;
int b;
};

sig temp[10];

stack<sig> trial;

Now I push a few "sig" elements to the "trial" stack. How do I access the second value (b) of the topmost element in the stack ?

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
9 years ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

You can use vector in the same way as stack

»
9 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
  1. If you want this functionality then vector is the DS you need, it has push_back and pop_back and you can perform binary_search on it.
  2. Use '.' operator, trial.top().b will do it for you.