Java Practice-It || 16.3 isSorted || implementing, ListNodes, LinkedLists

preview_player
Показать описание
Question:
Write a method isSorted that returns true if the list is in sorted (nondecreasing) order and returns false otherwise. An empty list is considered to be sorted.

Assume that you are adding this method to the LinkedIntList class as defined below:

public class LinkedIntList {
private ListNode front; // null for an empty list
...
}

Better code (change in line 14 & more comments):
public void firstLast(){
//if list is empty or if there is only one value
return;
}
    //storing the first value
ListNode first = front;
//moving the list forward one (getting rid of the original node)
//making temporary list
ListNode current = front;
//iterating through
}
//putting first value into last index and setting the next one to null
}
Рекомендации по теме
Комментарии
Автор

hey is this done recursively? pls respond

Javi_b