Guest User

Untitled

a guest
May 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include "Charstack.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. Charstack::Charstack() {
  7. stack_size = 0;
  8. }
  9.  
  10. bool Charstack::empty() {
  11. return stack_size == 0;
  12. }
  13.  
  14. void Charstack::push (StackElement_c item) {
  15. if(stack_size == CAPACITY)
  16. cout << "Stack is full!\n";
  17. else {
  18. stackArray[stack_size] = item;
  19. stack_size++;
  20. }
  21. }
  22.  
  23. StackElement_c Charstack::pop() {
  24. stack_size--;
  25. if(stack_size >= 0)
  26. return stackArray[stack_size];
  27. else
  28. return '\0';
  29. }
  30.  
  31. void Charstack::display() {
  32. for(int i = stack_size - 1; i >= 0; i--)
  33. cout << stackArray[i] << " ";
  34. }
Add Comment
Please, Sign In to add comment