Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class OwnQueue {
  4. ArrayList<Object> list;
  5.  
  6. public OwnQueue() {
  7. list = new ArrayList<Object>();
  8. }
  9.  
  10. public boolean add(Object o) {
  11. return list.add(o);
  12. }
  13.  
  14. public Object remove() {
  15. if (list.get(0) != null) {
  16. Object temp = list.get(0);
  17. list.remove(list.get(0));
  18. return temp;
  19. } else {
  20. System.out.println("Queue is empty");
  21. return null;
  22. }
  23. }
  24.  
  25. public static void main(String[] args) {
  26. OwnQueue que = new OwnQueue();
  27. que.add("one");
  28. que.add("two");
  29. que.remove();
  30. System.out.println(que);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement