Advertisement
karbaev

stack-array-simple

Feb 29th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int *s;
  6. int head=0;
  7.  
  8. void push (int x){
  9.     head++;
  10.     s[head]=x;
  11. }
  12.  
  13. int pop(){
  14.      head--;
  15.      return s[head+1];
  16. }
  17. int peek(){
  18.     return s[head];
  19. }
  20. int main()
  21. {
  22.     s = new int[1000];
  23.     s[0]=0;
  24.     push(1);
  25.     push(2);
  26.     push(3);
  27.     cout<<pop()<<endl;
  28.     cout<<pop()<<endl;
  29.     cout<<pop()<<endl;
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement