Traverse further only if there are at - least two nodes left
while ( temp != null && temp . next != null ) { if ( temp . data > temp . next . data ) { flag = false ; break ; } temp = temp . next . next ; } return flag ; }