Advertisement
Guest User

Pilas

a guest
Apr 24th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #ifndef __STACKS_H__
  2. #define __STACKS_H__
  3.  
  4. class StackS
  5. {
  6. private:
  7.  
  8. float* elems;
  9. unsigned int numElemes;
  10. unsigned int cap;
  11.  
  12. public:
  13. StackS(int cap) : cap(cap), numElemes(0), elems(new float[cap]) {
  14. /*
  15. this-> cap = cap;
  16. this-> _top = 0;
  17. this-> elems = new float(float) ;
  18. */
  19.  
  20. }
  21. ~StackS() { delete[] elems; }
  22.  
  23. bool is_Empty() {
  24. return numElemes == 0;
  25. }
  26.  
  27. bool is_full() {
  28. return numElemes == cap;
  29. }
  30.  
  31. bool push(float elem) {
  32.  
  33. if (!is_full()) {
  34. elems[numElemes++] = elem;
  35. return true;
  36. }
  37. else { return false; }
  38. }
  39. bool pop() {
  40. if (!is_Empty())
  41. {
  42. --numElemes;
  43. return true;
  44. }
  45. else { return false; }
  46. }
  47.  
  48. float top() {
  49. return elems[numElemes - 1];
  50. }
  51.  
  52.  
  53.  
  54.  
  55.  
  56. };
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. #endif // ! __STACKS_H__
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement