Advertisement
Guest User

Untitled

a guest
Oct 10th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1.  
  2. public class Main{
  3. public static void main(String arg[]){
  4. Queue q = new Queue(5);
  5.  
  6. q.push(5);
  7. q.push(4);
  8. q.push(3);
  9. q.push(2);
  10. q.push(1);
  11.  
  12. System.out.println(q.pop());
  13. System.out.println(q.pop());
  14. System.out.println(q.pop());
  15. System.out.println(q.pop());
  16. System.out.println(q.pop());
  17. }
  18. }
  19.  
  20. class Queue{
  21. int size;
  22. int it ;
  23. int poping_it;
  24. int array[] ;
  25. public Queue(int n){
  26. size = n;
  27. it = -1 ;
  28. poping_it = -1 ;
  29. array = new int[size];
  30. }
  31. public void push(int n){
  32. array[++it] = n ;
  33. }
  34. public int pop(){
  35. return array[++poping_it];
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement