Блог пользователя chari407

Автор chari407, история, 6 лет назад, По-английски

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 ?

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
6 лет назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

You can use vector in the same way as stack

»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
  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.