Link to home
Start Free TrialLog in
Avatar of needle176
needle176

asked on

Stacks

please explain to me how this for statement works:

assuming that stack is a class with stack type set to int and stack capacity to 5.  Give the content of myTop and myArray data memebers of s after code segment has been executed.

Stack s;
for (int i = 0; i<5; i++)  //please help me in this step, what is the first value of i
s.push(2*i);    //what are the values of all the i's please help me.
   s.pop();
   s.pop();

the answer according to my professor is myTop = 2 and myArray is 0, 2, 4, 6 but please help me understand why it is so. i had this question on an exam and i need to understand it.  
ASKER CERTIFIED SOLUTION
Avatar of lwinkenb
lwinkenb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial