#include"stack.h" bool SecondFromTop(Stack *s, ItemType &item) { ItemType top; // Pop twice if(!s->Pop(top)) return false; if(!s->Pop(item)) { s->Push(top); // Push back the first Pop if the second Pop fails return false; } // Restore by pushing in reverse order if(!s->Push(item) || !s->Push(top)) { // recall that || guarantees execution // left to right, so the order of Push // is correct here return false; // If either of the Pushes fails, // we return false to indicate that // the stack was not restored } return true; }