Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void add(Auto s) {
- size++;
- Node temp = new Node(s,null);
- // empty list
- if (top == null) {
- top = temp;
- return;
- }
- // if s is car object
- if (temp.getData() instanceof Car) {
- if(top.getData() instanceof Truck){
- Node current = top;
- top = temp;
- top.next = current;
- }
- if(top.getData() instanceof Car){
- Node current = top;
- top = temp;
- top.next = current;
- while(temp.next.getData() instanceof Car || temp.next != null){
- if (temp.next.getData().getBoughtOn().after(temp.getData().getBoughtOn())) {
- return;
- }
- if (temp.getData().getBoughtOn().after(temp.next.getData().getBoughtOn())) {
- Node temp1 = current.next;
- current = top;
- current.next = temp;
- temp.next = temp1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement