fork download
  1. #include <iostream>
  2. using namespace std;
  3. class Stack {
  4. private:
  5. int size;
  6. int Top;
  7. int *Arr;
  8.  
  9. public:
  10. Stack(int s) {
  11. Arr = new int[s];
  12. Top = -1;
  13. size = s;
  14. }
  15.  
  16. bool IsEmpty() {
  17. return (Top == -1);
  18. }
  19.  
  20. bool IsFull() {
  21. return (Top + 1 == size);
  22. }
  23.  
  24. void Push(int value) {
  25. if (IsFull()) {
  26. cout << "Can't Add .. Stack is full." << endl;
  27. } else {
  28. Top++;
  29. Arr[Top] = value;
  30. }
  31. }
  32.  
  33. int Pop() {
  34. if (IsEmpty()) {
  35. cout << "Can't Delete... Stack is empty." << endl;
  36. } else {
  37. return (Arr[Top--]);
  38. }
  39. }
  40.  
  41. int Peek() {
  42. if (IsEmpty()) {
  43. cout << "No Values ..." << endl;
  44. } else {
  45. return (Arr[Top]);
  46. }
  47. }
  48.  
  49. void Display() {
  50. for (int i = Top; i >= 0; i--) {
  51. cout << Arr[i] << " ";
  52. }
  53. cout << endl;
  54. }
  55. };
  56.  
  57.  
  58. int main() {
  59. // your code goes here
  60. return 0;
  61. }
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
Standard output is empty