java - How do I know if my LinkedList is already ordered? -


this question has answer here:

private static linkedlist<integer> melhormoto1 = new linkedlist<>(); 

i know can create new linkedlist, use newlinkedlist = melhormoto1;and collections.sort(newlinkedlist); , newlinkedlist.equals(melhormoto1 ); i'm working recursive function, newlinkedlist = melhormoto1; slow attribution. can check if linkedlist ordered method or something?

in java 8, can use comparators.isinorder(iterable) achieve list (or other ordered collection).

prior java 7, yourself: check list sorted in ascending order, iterate through , check current element cur greater or equal previous element prev each adjacent pair of elements.

change less or equal descending order. requires size() - 1 total checks.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -