-
Notifications
You must be signed in to change notification settings - Fork 0
/
PriorityQueue.cs
59 lines (50 loc) · 1.21 KB
/
PriorityQueue.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Puzzle15
{
class PriorityQueue
{
List<State> stateList;
public List<State> StateList
{
get
{
return stateList;
}
set
{
stateList = value;
}
}
public PriorityQueue()
{
stateList = new List<State>();
}
public PriorityQueue(List<State> sl)
{
stateList = new List<State>();
for (int i = 0; i < sl.Count; i++)
stateList.Add(sl[i]);
}
int Comparison(State s1, State s2)
{
double f1 = s1.Distance;
double f2 = s2.Distance;
if (f1 < f2)
return -1;
else if (f1 == f2)
return 0;
else
return +1;
}
public State ExtractMin()
{
stateList.Sort(Comparison);
State result = stateList[0];
stateList.RemoveAt(0);
return result;
}
}
}