Advertisement
karbaev

queue-array-simple

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