-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPriorityQueue.cs
More file actions
43 lines (33 loc) · 877 Bytes
/
PriorityQueue.cs
File metadata and controls
43 lines (33 loc) · 877 Bytes
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
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PriorityQueue<T> {
struct PElement {
public float priority;
public T data;
public PElement (float f, T d) {
priority = f;
data = d;
}
}
List<PElement> PList = new List<PElement>();
public void Add (T d, float priority) {
int i;
for (i = 0; i < PList.Count; i++) {
if (priority < PList[i].priority) break;
}
PList.Insert(i, new PElement(priority, d));
}
public void RemoveAt (int index) {
PList.RemoveAt(index);
}
public T Get (int index) {
return PList[index].data;
}
public float GetPriority(int index) {
return PList[index].priority;
}
public int Count {
get { return PList.Count; }
}
}