dimanche 4 janvier 2015

How does this "pop" function in a Stack implementation work?


Vote count:

0




I was reading a guide on ADTs for c++ and I came across this example of implementing a Stack using classes and I was confused about how the main function called and used this particular function.



bool Stack::is_empty()
{
return top == 0; // does this mean return top with the value 0?
}


function that calls it in main:



Stack st;
if(st.is_empty()) // How does this work if it's not passing a value to function?
cout << "it is full"


I don't understand how the is_empty function checks if our stack is empty, all I it doing is returning 0? Just how does it evaluate to true or false in the parameter if aren't even passing it anything?



asked 40 secs ago







How does this "pop" function in a Stack implementation work?

Aucun commentaire:

Enregistrer un commentaire