c++ - negatives in a stack while looping through it -


I am trying to write a function that tells the user the number of negative numbers in the stack. I stuck with the following and I am not able to get the right answer yet. I tested it with several test stacks. I think the problem is that how loops are kept. Any help will be appreciated!

  int negcount = 0; For (int i = 0; i    

< P> What will work for you here:
  int negcount = 0; While (mystack.size ()> 0) {if (mystack.top () & lt; 0) {negcount ++; Mystack.pop (); } And {mystack.pop (); }} Revenge crooks;    

Comments

Popular posts from this blog

Out of index C/C++ -

regex - PatternSyntaxException: while using String.ReplaceAll function in java? -

objective c - how Set autolayout for multiple dynamic buttons and labells in iOS? -