text: Check if linked list is sorted ( Iterative and Recursive ) | Linked list node ; function to Check Linked List is sorted in descending order or not ; Base cases ; Check first two nodes and recursively check remaining . ; Driver code
code: class Node { constructor ( ) { this . data = 0 ; this . next = null ; } } function isSortedDesc ( head ) { if ( head == null head . next == null ) return true ; return head . data > head . next . data && isSortedDesc ( head . next ) ; } function newNode ( data ) { var temp = new Node ( ) ; temp . next = null ; temp . data = data ; return temp ; } var head = newNode ( 7 ) ; head . next = newNode ( 5 ) ; head . next . next = newNode ( 4 ) ; head . next . next . next = newNode ( 3 ) ; if ( isSortedDesc ( head ) == true ) document . write ( " " ) ; else document . write ( " " ) ;