Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 6th, 2013  |  syntax: C++  |  size: 1.18 KB  |  views: 32  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include "enhanced-stack.hpp"
  2.  
  3. ENHANCED_STACK::ENHANCED_STACK() : STACK()
  4. {
  5. }
  6.  
  7. void ENHANCED_STACK::Print_Stack()
  8. {
  9.   NODE * temp = HEAD;
  10.  
  11.   cout << "Stack: ";
  12.  
  13.   if(Is_Empty())
  14.   {
  15.     cout << "<Empty>";
  16.   }
  17.   else
  18.   {
  19.     while (temp != NULL)
  20.     {
  21.       cout << setw(3) << temp->value;
  22.       temp = temp->link;
  23.     }
  24.   }
  25.  
  26.   cout << endl;
  27. }
  28.  
  29. void ENHANCED_STACK::Clean()
  30. {
  31.   int value;
  32.  
  33.   while(!Is_Empty())
  34.   {
  35.     Pop(value);
  36.   }
  37. }
  38.  
  39. void ENHANCED_STACK::Copy(STACK & S1)
  40. {
  41.   ENHANCED_STACK temp;
  42.   int value;
  43.  
  44.   Clean();
  45.  
  46.   while(!S1.Is_Empty())
  47.   {
  48.     S1.Pop(value);
  49.     temp.Push(value);
  50.   }
  51.  
  52.   while(!temp.Is_Empty())
  53.   {
  54.     temp.Pop(value);
  55.     Push(value);
  56.     S1.Push(value);
  57.   }
  58. }
  59.  
  60. int ENHANCED_STACK::Equal(STACK & S1)
  61. {
  62.   ENHANCED_STACK temp1;
  63.   ENHANCED_STACK temp2;
  64.  
  65.   int flag = 1;
  66.   int value1;
  67.   int value2;
  68.  
  69.   temp1.Copy(*this);
  70.   temp2.Copy(S1);
  71.  
  72.   while(!(temp1.Is_Empty() && temp2.Is_Empty()))
  73.   {
  74.     temp1.Pop(value1);
  75.     temp2.Pop(value2);
  76.  
  77.     if(value1 != value2)
  78.     {
  79.       flag = 0;
  80.       break;
  81.     }
  82.   }
  83.  
  84.   if(temp1.Is_Empty() && temp2.Is_Empty())
  85.   {
  86.     flag = 0;
  87.   }
  88.  
  89.   return flag;
  90. }