diff --git a/dotnet/MyOrganization/Employee.cs b/dotnet/MyOrganization/Employee.cs index 208bd8e..cf45f2f 100644 --- a/dotnet/MyOrganization/Employee.cs +++ b/dotnet/MyOrganization/Employee.cs @@ -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; } @@ -32,7 +32,7 @@ public Name GetName() override public string ToString() { - return name.ToString() + ": " + identifier; + return name.ToString(); } } } diff --git a/dotnet/MyOrganization/Organization.cs b/dotnet/MyOrganization/Organization.cs index e288ef8..69f145f 100644 --- a/dotnet/MyOrganization/Organization.cs +++ b/dotnet/MyOrganization/Organization.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.ConstrainedExecution; using System.Text; using System.Threading.Tasks; @@ -9,7 +10,7 @@ namespace MyOrganization internal abstract class Organization { private Position root; - + private int iden; public Organization() { root = CreateOrganization(); @@ -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 queue = new Queue(); + + 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() diff --git a/dotnet/MyOrganization/Position.cs b/dotnet/MyOrganization/Position.cs index d02eb30..d4177f6 100644 --- a/dotnet/MyOrganization/Position.cs +++ b/dotnet/MyOrganization/Position.cs @@ -10,7 +10,7 @@ namespace MyOrganization { internal class Position { - private string title; + public string title; private Employee? employee; private HashSet directReports;