Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. public void add(Auto s) {
  2. size++;
  3. Node temp = new Node(s,null);
  4.  
  5. // empty list
  6. if (top == null) {
  7. top = temp;
  8. return;
  9. }
  10.  
  11. // if s is car object
  12. if (temp.getData() instanceof Car) {
  13. if(top.getData() instanceof Truck){
  14. Node current = top;
  15. top = temp;
  16. top.next = current;
  17. }
  18. if(top.getData() instanceof Car){
  19. Node current = top;
  20. top = temp;
  21. top.next = current;
  22.  
  23. while(temp.next.getData() instanceof Car || temp.next != null){
  24. if (temp.next.getData().getBoughtOn().after(temp.getData().getBoughtOn())) {
  25. return;
  26. }
  27. if (temp.getData().getBoughtOn().after(temp.next.getData().getBoughtOn())) {
  28. Node temp1 = current.next;
  29. current = top;
  30. current.next = temp;
  31. temp.next = temp1;
  32. }
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement