Skip to content

Commit e06431d

Browse files
paramagparamag
authored andcommitted
Parking lot design and implementation.
1 parent a426844 commit e06431d

22 files changed

Lines changed: 428 additions & 26 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@
2020
/DataStructures/Heap/bin/Debug
2121
/Design/ParallelTasksProcessor/bin/Debug
2222
/Design/ParallelTasksProcessor/obj/Debug
23+
/DataStructures/PriorityQueue/bin/Debug
24+
/DataStructures/PriorityQueue/obj/Debug
25+
/Design/Elevator/bin/Debug
26+
/Design/Elevator/obj/Debug
30 KB
Binary file not shown.

DataStructures/DataStructures.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataStructures.Libraries.He
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataStructures.Libraries.Graph", "Graph\DataStructures.Libraries.Graph.csproj", "{6EB3565B-2658-42A7-80CB-223B6E42013A}"
99
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataStructures.Libraries.PriorityQueue", "PriorityQueue\DataStructures.Libraries.PriorityQueue.csproj", "{D9DBDE6D-6DE9-4B89-A3D7-1760B6ECBF3D}"
11+
EndProject
1012
Global
1113
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1214
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +23,10 @@ Global
2123
{6EB3565B-2658-42A7-80CB-223B6E42013A}.Debug|Any CPU.Build.0 = Debug|Any CPU
2224
{6EB3565B-2658-42A7-80CB-223B6E42013A}.Release|Any CPU.ActiveCfg = Release|Any CPU
2325
{6EB3565B-2658-42A7-80CB-223B6E42013A}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{D9DBDE6D-6DE9-4B89-A3D7-1760B6ECBF3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{D9DBDE6D-6DE9-4B89-A3D7-1760B6ECBF3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{D9DBDE6D-6DE9-4B89-A3D7-1760B6ECBF3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{D9DBDE6D-6DE9-4B89-A3D7-1760B6ECBF3D}.Release|Any CPU.Build.0 = Release|Any CPU
2430
EndGlobalSection
2531
GlobalSection(SolutionProperties) = preSolution
2632
HideSolutionNode = FALSE

DataStructures/Heap/Heap.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@ public abstract class Heap<TKey, TObject>
1818
// Use the heap object to heapify the collection.
1919
public TKey[] HeapObject;
2020

21-
public Dictionary<TKey, TObject> dict;
22-
2321
public Heap(int size = DefaultHeapSize, HeapType heapType = HeapType.MinHeap)
2422
{
2523
this.HeapSize = size;
2624
this.HeapType = heapType;
27-
28-
this.dict = new Dictionary<TKey, TObject>();
2925
}
3026

3127
public abstract void SiftUpOperation();
@@ -34,18 +30,16 @@ public Heap(int size = DefaultHeapSize, HeapType heapType = HeapType.MinHeap)
3430

3531
public void Insert(TKey key, TObject value)
3632
{
37-
this.dict.Add(key, value);
38-
3933
this.HeapObject[this.counter] = key;
4034

4135
// Heapify using Sift up operation.
4236
this.SiftUpOperation();
4337
this.counter += 1;
4438
}
4539

46-
public TObject GetAndDelete()
40+
public TKey Delete()
4741
{
48-
TKey keyValue = this.HeapObject[0];
42+
TKey keyValue = this.Get();
4943

5044
// Delete the root node from the heap.
5145
this.HeapObject[0] = this.HeapObject[this.counter];
@@ -54,11 +48,14 @@ public TObject GetAndDelete()
5448
// Heapify using Sift down operation.
5549
this.SiftDownOperation();
5650

57-
// Remove the value from the dictionary.
58-
TObject valueObject = this.dict[keyValue];
59-
this.dict.Remove(keyValue);
51+
return keyValue;
52+
}
53+
54+
public TKey Get()
55+
{
56+
TKey keyValue = this.HeapObject[0];
6057

61-
return valueObject;
58+
return keyValue;
6259
}
6360

6461
protected int FindParent(int position)

DataStructures/Heap/MinHeap.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ namespace Algorithm.Libraries.Heap
88
{
99
public class MinHeap<TKey, TObject> : Heap<TKey, TObject>
1010
{
11+
public MinHeap(int size = DefaultHeapSize, HeapType heapType = HeapType.MinHeap)
12+
: base(size, heapType)
13+
{
14+
}
15+
1116
public override void SiftDownOperation()
1217
{
1318
// Always start at the root node of the heap.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{D9DBDE6D-6DE9-4B89-A3D7-1760B6ECBF3D}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>DataStructures.Libraries.PriorityQueue</RootNamespace>
11+
<AssemblyName>DataStructures.Libraries.PriorityQueue</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="System" />
34+
<Reference Include="System.Core" />
35+
<Reference Include="System.Xml.Linq" />
36+
<Reference Include="System.Data.DataSetExtensions" />
37+
<Reference Include="Microsoft.CSharp" />
38+
<Reference Include="System.Data" />
39+
<Reference Include="System.Net.Http" />
40+
<Reference Include="System.Xml" />
41+
</ItemGroup>
42+
<ItemGroup>
43+
<Compile Include="PriorityQueue.cs" />
44+
<Compile Include="Properties\AssemblyInfo.cs" />
45+
</ItemGroup>
46+
<ItemGroup>
47+
<ProjectReference Include="..\Heap\DataStructures.Libraries.Heap.csproj">
48+
<Project>{668f095a-10d6-46dc-ae72-55f5101eec55}</Project>
49+
<Name>DataStructures.Libraries.Heap</Name>
50+
</ProjectReference>
51+
</ItemGroup>
52+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
53+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
54+
Other similar extension points exist, see Microsoft.Common.targets.
55+
<Target Name="BeforeBuild">
56+
</Target>
57+
<Target Name="AfterBuild">
58+
</Target>
59+
-->
60+
</Project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Algorithm.Libraries.Heap;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace DataStructures.Libraries.PriorityQueue
9+
{
10+
public class PriorityQueue<TKey, TObject>
11+
{
12+
Dictionary<TKey, TObject> dict;
13+
MinHeap<TKey, TObject> minHeap = new MinHeap<TKey, TObject>();
14+
15+
public PriorityQueue(int size)
16+
{
17+
this.dict = new Dictionary<TKey, TObject>();
18+
this.minHeap = new MinHeap<TKey, TObject>(size, HeapType.MinHeap);
19+
}
20+
21+
public void Insert(TKey key, TObject value)
22+
{
23+
this.minHeap.Insert(key, value);
24+
25+
this.dict.Add(key, value);
26+
}
27+
28+
public TObject Delete()
29+
{
30+
TKey keyValue = this.minHeap.Get();
31+
32+
// Remove the value from the dictionary.
33+
TObject valueObject = this.dict[keyValue];
34+
this.dict.Remove(keyValue);
35+
36+
return valueObject;
37+
}
38+
39+
public TObject Get()
40+
{
41+
TKey keyValue = this.minHeap.Get();
42+
43+
// Remove the value from the dictionary.
44+
TObject valueObject = this.dict[keyValue];
45+
46+
return valueObject;
47+
}
48+
}
49+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("PriorityQueue")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("PriorityQueue")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("d9dbde6d-6de9-4b89-a3d7-1760b6ecbf3d")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

Design/.vs/Design/v14/.suo

25.5 KB
Binary file not shown.

Design/Design.sln

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DataStructure.Libraries", "
1515
EndProject
1616
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataStructures.Libraries.Graph", "..\DataStructures\Graph\DataStructures.Libraries.Graph.csproj", "{6EB3565B-2658-42A7-80CB-223B6E42013A}"
1717
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataStructures.Libraries.PriorityQueue", "..\DataStructures\PriorityQueue\DataStructures.Libraries.PriorityQueue.csproj", "{D9DBDE6D-6DE9-4B89-A3D7-1760B6ECBF3D}"
19+
EndProject
1820
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataStructures.Libraries.Heap", "..\DataStructures\Heap\DataStructures.Libraries.Heap.csproj", "{668F095A-10D6-46DC-AE72-55F5101EEC55}"
1921
EndProject
22+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Design.Libraries.Elevator", "Elevator\Design.Libraries.Elevator.csproj", "{4B17ACEE-1EE1-473C-A1EF-4B962936214C}"
23+
EndProject
2024
Global
2125
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2226
Debug|Any CPU = Debug|Any CPU
@@ -43,16 +47,25 @@ Global
4347
{6EB3565B-2658-42A7-80CB-223B6E42013A}.Debug|Any CPU.Build.0 = Debug|Any CPU
4448
{6EB3565B-2658-42A7-80CB-223B6E42013A}.Release|Any CPU.ActiveCfg = Release|Any CPU
4549
{6EB3565B-2658-42A7-80CB-223B6E42013A}.Release|Any CPU.Build.0 = Release|Any CPU
50+
{D9DBDE6D-6DE9-4B89-A3D7-1760B6ECBF3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51+
{D9DBDE6D-6DE9-4B89-A3D7-1760B6ECBF3D}.Debug|Any CPU.Build.0 = Debug|Any CPU
52+
{D9DBDE6D-6DE9-4B89-A3D7-1760B6ECBF3D}.Release|Any CPU.ActiveCfg = Release|Any CPU
53+
{D9DBDE6D-6DE9-4B89-A3D7-1760B6ECBF3D}.Release|Any CPU.Build.0 = Release|Any CPU
4654
{668F095A-10D6-46DC-AE72-55F5101EEC55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
4755
{668F095A-10D6-46DC-AE72-55F5101EEC55}.Debug|Any CPU.Build.0 = Debug|Any CPU
4856
{668F095A-10D6-46DC-AE72-55F5101EEC55}.Release|Any CPU.ActiveCfg = Release|Any CPU
4957
{668F095A-10D6-46DC-AE72-55F5101EEC55}.Release|Any CPU.Build.0 = Release|Any CPU
58+
{4B17ACEE-1EE1-473C-A1EF-4B962936214C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
59+
{4B17ACEE-1EE1-473C-A1EF-4B962936214C}.Debug|Any CPU.Build.0 = Debug|Any CPU
60+
{4B17ACEE-1EE1-473C-A1EF-4B962936214C}.Release|Any CPU.ActiveCfg = Release|Any CPU
61+
{4B17ACEE-1EE1-473C-A1EF-4B962936214C}.Release|Any CPU.Build.0 = Release|Any CPU
5062
EndGlobalSection
5163
GlobalSection(SolutionProperties) = preSolution
5264
HideSolutionNode = FALSE
5365
EndGlobalSection
5466
GlobalSection(NestedProjects) = preSolution
5567
{6EB3565B-2658-42A7-80CB-223B6E42013A} = {7AA00273-B559-47D6-8C35-1D3CE2F086F2}
68+
{D9DBDE6D-6DE9-4B89-A3D7-1760B6ECBF3D} = {7AA00273-B559-47D6-8C35-1D3CE2F086F2}
5669
{668F095A-10D6-46DC-AE72-55F5101EEC55} = {7AA00273-B559-47D6-8C35-1D3CE2F086F2}
5770
EndGlobalSection
5871
EndGlobal

0 commit comments

Comments
 (0)