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

Показать описание
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
}
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
}
Java Practice-It || 16.3 isSorted || implementing, ListNodes, LinkedLists
Java Practice-It || 16.4 lastIndexOf || implementing, ListNodes, LinkedLists
Java Practice-It || 16.1 set || implementing, ListNodes, LinkedLists
Java Practice-It || 16.9 linkedNodes9 || ListNodes, LinkedLists
Java Practice-It || 16.8 switchPairs (pt.1) || implementing, ListNodes, LinkedLists
Java Practice-It || 16.12 linkedNodes12 || ListNodes, LinkedLists
Java Practice-It || 16.23 linkedNodes23 || ListNodes, LinkedLists
Java Practice-It || 16.11 linkedNodes11 || ListNodes, LinkedLists
Java Practice-It || 16.7 deleteBack (pt.1) || implementing, ListNodes, LinkedLists
Java Practice-It || 16.14 linkedNodes14 || ListNodes, LinkedLists
Java Practice-It || 16.24 linkedNodes24 || ListNodes, LinkedLists
Java Practice It || 5.16 isPrime || method with int parameter & boolean return, for loop, debug...
Java Practice It | Exercise 7.16: append | arrays, syntax, array basics, condition
Java Practice-It || 16.5 countDuplicates (pt.1) || implementing, ListNodes, LinkedLists
Java Program #17 - Sort an Array of Integers in ascending order
Java Practice-It || 16.30 firstLast || implementing, ListNodes, LinkedLists
Exercise 7.18 (evenBeforeOdd) Java Tutorial || Practice-It
Java Practice It | Exercise 14.6: rearrange | Collections, #stacks and #queues , stacks, queues
LeetCode 16 | 3Sum Closest | Solution Explained (Java + Whiteboard)
Java Practice It | Self-Check 7.24: arrayMystery1 | arrays, syntax, array basics
Java Practice It || 2.17 SlashFigure2 || nested for loops
Java Practice It | Exercise 7.9: minGap | arrays, array methods, for loop, conditions
8 patterns to solve 80% Leetcode problems
LeetCode was HARD until I Learned these 15 Patterns
Комментарии