-3

in this code i want to put integers in a double list and then to check if the list is sorted or not so in a method i try to compare the value the first object of the list with the second, then the second with the third etc. what i dont remember/know is how you compare them

public class Ergasthrio6 {

    public static boolean isSorted(DoubleLinkedList dl) throws ListEmptyException{
        DoubleLinkedList selectedItem = (DoubleLinkedList) dl.removeFirst();
        dl.insertLast(selectedItem);
        DoubleLinkedList tmp;
        for (int i=1; i < dl.size(); i++){
            tmp = (DoubleLinkedList) dl.removeFirst();
            dl.insertLast(tmp);
            if (selectedItem < tmp)) <-----here
               return false; 
            else
               selectedItem = tmp;
            tmp = tmp.removeFirst();
        }
    }

    public static void main(String[] args) throws ListEmptyException {
        // TODO code application logic here
        DoubleLinkedList dl = new DoubleLinkedList();
        for (int i=0; i < 10; i++)
            dl.insertFirst(UserInput.getInteger());
        isSorted(dl);
    }
}
dur
  • 15,689
  • 25
  • 79
  • 125

1 Answers1

0

an easy approach would be to create a method in which each variable of the two objects will be compared. returning a boolean or a -1, 1 kind of value would suffice in case of less than or not scenarios.