From 81ba9eb66f8284d8760012973f84cdbe617ceb94 Mon Sep 17 00:00:00 2001 From: pants Date: Mon, 21 Sep 2026 14:16:34 -0700 Subject: init --- debugging/Debugging.java | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 debugging/Debugging.java (limited to 'debugging/Debugging.java') diff --git a/debugging/Debugging.java b/debugging/Debugging.java new file mode 100644 index 0000000..a9e301f --- /dev/null +++ b/debugging/Debugging.java @@ -0,0 +1,54 @@ +import java.util.*; + +public class Debugging { + public static void main(String[] args) { + Map> testMap = new TreeMap<>(); + Set c121 = arrToSet(new int[]{42, 17, 42, 42}); + Set c122 = arrToSet(new int[]{10, 12, 14}); + Set c123 = arrToSet(new int[]{100, 99, 98, -97}); + testMap.put("cse121", c121); + testMap.put("cse122", c122); + testMap.put("cse123", c123); + + Map> deepCopyMap = deepCopy(testMap); + + if (deepCopyMap.isEmpty()) { + System.out.println("{}"); + } else { + String line = ""; + for (String key : deepCopyMap.keySet()) { + line += key + "=" + deepCopyMap.get(key).toString() + ", "; + } + System.out.println("{" + line.substring(0, line.length() - 2) + "}"); + } + } + + public static Set arrToSet(int[] arr) { + Set s = new TreeSet<>(); + for (int num : arr) { + s.add(num); + } + return s; + } + + // Produces and returns a "deep copy" of the parameter map, which has the same + // structure and values as the parameter, but with all internal data structures + // and values copied. After calling this method, modifying the parameter or + // return value should NOT affect the other. + // + // Parameters: + // inputMap - the map to duplicate + // + // Returns: + // A deep copy of the parameter map. + public static Map> deepCopy(Map> inputMap) { + Map> deepCopy = new TreeMap<>(); + + for (String key : inputMap.keySet()) { + Set inputSet = new TreeSet<>(inputMap.get(key)); + // Set inputSet = inputMap.get(key); + deepCopy.put(key, inputSet); + } + return deepCopy; + } +} -- cgit v1.2.3