CP-1.012 Java Tutorial - Map.Entry and var
Problem: Sort (https://open.kattis.com/problems/sort) I discuss yet another way to traverse through a map: using Map.Entry, which we'll also use to 'sort' the map. I'm also starting to use the var keyword which makes life easier. I realise that I didn't fully explain how the sort works, but it's actually very simple. For descending order, given a and b, we want to return a positive number if a is less than b, and a negative number otherwise (or 0 if a == b). You can read up on Java compareTo. Note that my compareTo implementation will have a.compareTo(b) returning a positive number if a is greater than b BUT this is because by default sorting is done in ascending order. We have to flip it for this problem. Video Sections: 0:00 - Problem description 2:33 - Start of solution - LinkedHashMap 3:27 - var keyword 5:34 - Using Map.Entry 8:34 - Porting the map into an ArrayList 11:12 - Printing the output 13:42 - Summary Please note that all views and opinions expressed in this video are my own and does not reflect that of Kattis or any other person/organisation mentioned in the video.
Download
0 formatsNo download links available.