Skip to content

Some Improvement Suggest. #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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)