How would I make my custom generic type linked list in Java sorted?
I am writing my own linked list in java that is of generic type instead of using the java collections linked list. The add method for the linked list is made up of the following code: public void add(T item, int position) { Node<T> addThis = new Node<T>(item); Node<T> prev = head; int i; if(position <= 0) { System.out.println("Error: Cannot add element before position 1."); } else if(position == 1) { addThis.setNext(head); head = addThis; } else { for(i = 1; i < position-1; i++) { prev = prev.getNext(); if(prev == null) { System.out.println("Cannot add beyond end of list"); } } // end for