Skip to content
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

Hire Method Fix Using BreadFirst Search Algorithm #21

Open
wants to merge 3 commits into
base: main
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
6 changes: 3 additions & 3 deletions dotnet/MyOrganization/Employee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ internal class Employee
private int identifier;
private Name name;

public Employee(int identifier, Name name)
public Employee(Name name, int Identifier)
{
if (name == null)
throw new Exception("name cannot be null");
this.identifier = identifier;
this.identifier = Identifier;
this.name = name;
}

Expand All @@ -32,7 +32,7 @@ public Name GetName()

override public string ToString()
{
return name.ToString() + ": " + identifier;
return name.ToString();
}
}
}
39 changes: 37 additions & 2 deletions dotnet/MyOrganization/Organization.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;

Expand All @@ -9,7 +10,7 @@ namespace MyOrganization
internal abstract class Organization
{
private Position root;

private int iden;
public Organization()
{
root = CreateOrganization();
Expand All @@ -24,10 +25,44 @@ public Organization()
* @param title
* @return the newly filled position or empty if no position has that title
*/
/*
APPROACH EXPLANATION : The CreateOrganization is built like a Tree with multiple Levels .
One of the Recommended Approaches that is done iteratively is using a Queue by exploring each position and its Direct Reported Positions..
*/
public Position? Hire(Name person, string title)
{
//your code here
return null;
Position current = root;
iden = 0;
Queue<Position> queue = new Queue<Position>();

queue.Enqueue(current);

while (queue.Count > 0)
{
Position cur = queue.Dequeue();
// validate if the position has the that title
if (cur.title == title)
{
// if not filled...
if(!cur.IsFilled())
{
cur.SetEmployee(new Employee(person,iden++));
return cur;
}
}
else
{
//enqueuing the current position Direct Reports into the Queue for exploration...
foreach (Position pos in cur.GetDirectReports())
{
queue.Enqueue(pos);
}
}
}
// return empty is no position has title
// different use case..
return new Position(string.Empty);
}

override public string ToString()
Expand Down
2 changes: 1 addition & 1 deletion dotnet/MyOrganization/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace MyOrganization
{
internal class Position
{
private string title;
public string title;
private Employee? employee;
private HashSet<Position> directReports;

Expand Down