From bdf23813d0256f55b676b99981d32db1a3baae60 Mon Sep 17 00:00:00 2001 From: Joonsoo Kim Date: Tue, 26 Apr 2022 23:52:41 +0900 Subject: [PATCH 1/3] Adding Another Merge_Sorted_Arrays.cs I tried another solution in CS. --- 1. DS - Array/Merge_Sorted_Arrays_2.cs | 65 ++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 1. DS - Array/Merge_Sorted_Arrays_2.cs diff --git a/1. DS - Array/Merge_Sorted_Arrays_2.cs b/1. DS - Array/Merge_Sorted_Arrays_2.cs new file mode 100644 index 0000000..a4721e9 --- /dev/null +++ b/1. DS - Array/Merge_Sorted_Arrays_2.cs @@ -0,0 +1,65 @@ +using System; + +class MainClass +{ + static int[] MergeSortedArrays(int[] array1, int[] array2) + { + int[] result = new int[array1.Length + array2.Length]; + + int array1Item = array1[0]; + int array2Item = array2[0]; + int i = 0; + int j = 1; + int k = 1; + + while (i < result.Length) + { + if(array1Item > -1 && (array1Item < array2Item || array2Item < 0)) + { + result[i] = array1Item; + if(j < array1.Length) + { + array1Item = array1[j]; + j++; + } + else + { + array1Item = -1; + } + } + else + { + result[i] = array2Item; + if (k < array2.Length) + { + array2Item = array2[k]; + k++; + } + else + { + array2Item = -1; + } + } + + i++; + } + + return result; + } + // 0, 3, 4, 4, 6, 30, 31 + + + static void Main() + { + int[] array1 = new int[] {0, 3, 4, 31}; + int[] array2 = new int[] {4, 6, 30}; + // int[] array2 = new int[] {4, 6, 30, 32, 34}; + + int[] newArray = MergeSortedArrays(array1, array2); + + foreach(int item in newArray) + { + Console.Write(item.ToString() + " "); + } + } +} From 20e3d045c4a10378b839387ef2ee50a29bc5ccf4 Mon Sep 17 00:00:00 2001 From: Joonsoo Kim Date: Wed, 27 Apr 2022 23:25:19 +0900 Subject: [PATCH 2/3] Out of Index Error fix! --- 2. DS - HashTable/HashTable_Implementation.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/2. DS - HashTable/HashTable_Implementation.cs b/2. DS - HashTable/HashTable_Implementation.cs index 3f1d6a5..697553a 100644 --- a/2. DS - HashTable/HashTable_Implementation.cs +++ b/2. DS - HashTable/HashTable_Implementation.cs @@ -69,7 +69,8 @@ public List keys() { if (this.data[i] != null) { - for (int j = 0; j < length; j++) + // for (int j = 0; j < length; j++) // length is 50 & Out of Index Error + for (int j = 0; j < this.data[i].Count; j++) // check collisions { result.Add(this.data[i][j].key); } @@ -86,4 +87,4 @@ static void Main(string[] args) //Console.Write(h.get("apples")); h.keys(); } - } \ No newline at end of file + } From d03f9035670b3491e4c5533416dc4a0267ab1590 Mon Sep 17 00:00:00 2001 From: Joonsoo Kim Date: Tue, 19 Jul 2022 02:07:41 +0900 Subject: [PATCH 3/3] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 9bfd33b..0a4d22b 100644 --- a/README.md +++ b/README.md @@ -15,3 +15,6 @@ - Traversals * BFS * DFS + +### Testing +[Replit Web Testing of the Codes] (https://replit.com/@bear8203/algorithm-study-c-sharp?v=1#README.md)