Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions 1. DS - Array/Merge_Sorted_Arrays_2.cs
Original file line number Diff line number Diff line change
@@ -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() + " ");
}
}
}
5 changes: 3 additions & 2 deletions 2. DS - HashTable/HashTable_Implementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public List<string> 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);
}
Expand All @@ -86,4 +87,4 @@ static void Main(string[] args)
//Console.Write(h.get("apples"));
h.keys();
}
}
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)