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

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -