Commit 7b5d33f0 authored by Cody A Burchett's avatar Cody A Burchett

-m comments for heap

parent 30954f53
......@@ -10,12 +10,15 @@ public class Heap <Tile> where Tile : HeapItem<Tile>{
//add heapIndex, compareTo to tile class
//compare fCost of node then hCost
//item.compareTo(item2) should return pos if item is less than item2, neg if item is greater than item2
//create heap
public Heap(int maxSize)
{
heapTiles = new Tile[maxSize];
}
//add item into heap and sort it into position
public void Add(Tile item)
{
item.heapIndex = itemCount;
......@@ -24,6 +27,7 @@ public class Heap <Tile> where Tile : HeapItem<Tile>{
itemCount++;
}
//remove first tile and resort heap
public Tile RemoveFirst()
{
Tile first = heapTiles[0];
......@@ -34,11 +38,13 @@ public class Heap <Tile> where Tile : HeapItem<Tile>{
return first;
}
//resort item position
public void UpdateItem(Tile item)
{
SortUp(item);
}
public int Count
{
get
......@@ -47,11 +53,13 @@ public class Heap <Tile> where Tile : HeapItem<Tile>{
}
}
//does heap contain item
public bool Contains(Tile item)
{
return Equals(heapTiles[item.heapIndex], item);
}
//sort tile lower into heap
void SortDown(Tile item)
{
while (true)
......@@ -88,6 +96,7 @@ public class Heap <Tile> where Tile : HeapItem<Tile>{
}
}
//sort item higher into heap
void SortUp(Tile item)
{
int indexOfParent = (item.heapIndex - 1) / 2;
......@@ -108,6 +117,7 @@ public class Heap <Tile> where Tile : HeapItem<Tile>{
}
}
//swap tiles
void Swap(Tile item1, Tile item2)
{
heapTiles[item1.heapIndex] = item2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment