Skip to content
Merged
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
10 changes: 10 additions & 0 deletions ElevatorAlgorithm/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ElevatorAlgorithm
{
class Class1
{
}
}
52 changes: 38 additions & 14 deletions ElevatorAlgorithm/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.ComponentModel.Design;

namespace ElevatorAlgorithm
{
Expand All @@ -15,6 +16,8 @@ public interface ElevatorInterface
void moveUp(int z);
void moveDown(int z);
void moveNext(int floor, int z);
int getIsIdle();
int setIsIdle(int a);

}

Expand All @@ -26,6 +29,7 @@ public class Elevator : ElevatorInterface
private int currentFloor;
private int people;
private int sum;
private int isIdle;


public int getSum()
Expand Down Expand Up @@ -121,8 +125,17 @@ public void moveDown(int z)

}

public int getIsIdle()
{
return isIdle;
}

}
public int setIsIdle(int a)
{
this.isIdle += a;
return isIdle;
}
}

class Program
{
Expand All @@ -141,7 +154,7 @@ static void Main(string[] args)

}

Elevator change = null; // Temporary Object
Elevator change = null; // Temporary Object

while (true)
{
Expand All @@ -163,7 +176,7 @@ static void Main(string[] args)

int z = 0;

for (int i = 0; i < numFloors; i++)
for (int i = 0; i < numFloors; i++)
{

// Selecting the floor where people are waiting
Expand All @@ -188,7 +201,7 @@ static void Main(string[] args)
// Choosing the BEST ELEVATOR for that location
int[] unsorted = new int[elevator.Length];
int[] sorted = new int[elevator.Length];

for (int j = 0; j < elevator.Length; j++)
{
unsorted[j] = Math.Abs(floor[i] - elevator[j].getCurrentFloor());
Expand All @@ -197,16 +210,26 @@ static void Main(string[] args)

Array.Sort(sorted);

for (int k = 0; k < elevator.Length; k++)
for (int j = 0; j < sorted.Length; j++)
{
if (sorted[0] == unsorted[k])
{
change = elevator[k];
z = k + 1;
break;
}
}
for (int k = 0; k < elevator.Length; k++)
{

{
if (elevator[k].getIsIdle() == 0 && sorted[j] == unsorted[k])
{
change = elevator[k];
z = k + 1;
elevator[k].setIsIdle(1);
Console.WriteLine("Elevator " + z + " is selected and idle is set to " + elevator[k].getIsIdle());
goto LoopEnd;

}
}
}
}
LoopEnd:
//sfs
// Acknowledging the number of people waiting for the elevator on selected floor
while (true)
{
Expand Down Expand Up @@ -287,13 +310,14 @@ static void Main(string[] args)

}

// forwarding the values from temporary elevator object to desired elevator
// object
// forwarding the values from temporary elevator object to desired elevator object
for (int k = 0; k < elevator.Length; k++)
{
if (z == k + 1)
{
elevator[k] = change;
elevator[k].setIsIdle(-1);
Console.WriteLine("Elevator " + z + " has ended its action and idle is set to " + elevator[k].getIsIdle());
break;
}

Expand Down