SHARE
TWEET

Untitled

a guest May 25th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. template <class Item>
  2. class Stack
  3. {
  4.     struct Element
  5.     {
  6.         double inf;
  7.         Element *next;
  8.         Element(double x, Element *p) : inf(x), next(p)
  9.         {
  10.         }
  11.     };
  12.     Element *head;
  13. public:
  14.     Stack() :head(0)
  15.     {
  16.     }
  17.     bool Empty()
  18.     {
  19.         return head == 0;
  20.     }
  21.     double Pop()
  22.     {
  23.         if (Empty())
  24.         {
  25.             return 0;
  26.         }
  27.         Element *r = head;
  28.         double i = r->inf;
  29.         head = r->next;
  30.         delete r;
  31.         return i;
  32.     }
  33.     void Push(double data)
  34.     {
  35.         head = new Element(data, head);
  36.     }
  37.     double Top()
  38.     {
  39.         if (Empty())
  40.         {
  41.             return 0;
  42.         }
  43.         else
  44.         {
  45.             return head->inf;
  46.         }
  47.     }
  48. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top