Listing 2 The C++ version of Listing 1

class StrStack {
   char * itemPtrs[5U];
   unsigned items;
  public:
   StrStack() { items = 0U; }
   int full() { return !(5U - items); }
   unsigned depth() { return items; }
   int push(char * itemPtr);
   char * top()
      { return (items? itemPtrs[items-1] : 0); }
   char * pop()
      { return (items? itemPtrs[--items] : 0); }
};

int StrStack::push(char * itemPtr)
{
   if (!full() && itemPtr) {
      itemPtrs[items++] = itemPtr;
      return 1;
   }
   return 0;
}

#include <iostream.h>
#include <iomanip.h>

main()
{
   StrStack ToDo;

   ToDo.push("wash car");
   ToDo.push("cut grass");
   ToDo.push("buy groceries");
   ToDo.push("cash paycheck");
   while (ToDo.top())
      cout << ToDo.pop() << endl;
   return 0;
}
/* End of File */