All pastes #358171 Raw Edit

Untitled

public php v1 · immutable
·published 2007-02-16 02:44 UTC
rendered paste body
#ifndef STACK_HPP#define STACK_Htemplate <class T> class Stack {  private:    struct item {        T data;        item *prior;    };    item *active;    int siz;  public:    Stack() : active(0), siz(0) {}    bool empty() {        return !siz;                             }    T pop() {        T oldData;        if(siz) {            item *temp(active->prior);            oldData = active->data;            delete active;            active = temp;            --siz;        }        return oldData;                          }                                  void push(T newData = 0) {        item *newItem(new item);        newItem->data = newData;        newItem->prior = siz ? active : 0;        active = newItem;        ++siz;                                   }    T xchg(T newData = 0) {        T oldData(active->data);        active->data = newData;        return oldData;                          }    int size() {        return siz;                              }    T top() {        return active->data;                     }};#endif