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() + " "); + } + } +} 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 + } 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)