本文整理汇总了C#中Heap.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# Heap.Remove方法的具体用法?C# Heap.Remove怎么用?C# Heap.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Heap
的用法示例。
在下文中一共展示了Heap.Remove方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoHeap
static void DoHeap()
{
Heap<Person> heap = new Heap<Person>();
//insert some people with dependents in no particular order
heap.Insert(new Person(4));
heap.Insert(new Person(1));
heap.Insert(new Person(8));
heap.Insert(new Person(0));
heap.Insert(new Person(13)); //this will be removed first
heap.Insert(new Person(2));
heap.Remove(); //person with 13 dependents is no longer in the heap
Console.WriteLine(heap.ToString());
}
示例2: RemoveRootTest
public void RemoveRootTest()
{
Heap<int> actual = new Heap<int> {33, 12, 41, 15, 60};
Heap<int> expected = new Heap<int> {15, 33, 41, 60};
Assert.IsTrue(actual.Remove(12));
Assert.AreEqual(4, actual.Count);
CollectionAssert.AreEqual(expected, actual);
}
示例3: RemoveRightChildLessThanLeftTest
public void RemoveRightChildLessThanLeftTest()
{
Heap<int> actual = new Heap<int> {5, 3, 8, 10, 6, 11, 12, 13};
Heap<int> expected = new Heap<int> {3, 6, 8, 10, 13, 11, 12};
Assert.IsTrue(actual.Remove(5));
Assert.AreEqual(7, actual.Count);
CollectionAssert.AreEqual(expected, actual);
}
示例4: RemoveMaxRightChildGreaterTest
public void RemoveMaxRightChildGreaterTest()
{
Heap<int> actual = new Heap<int>(Strategy.Max) {46, 23, 44, 66, 51, 32, 17, 8};
Heap<int> expected = new Heap<int>(Strategy.Max) {66, 46, 44, 23, 8, 32, 17};
Assert.IsTrue(actual.Remove(51));
Assert.AreEqual(7, actual.Count);
CollectionAssert.AreEqual(expected, actual);
}
示例5: RemoveMaxHeapTest
public void RemoveMaxHeapTest()
{
Heap<int> actual = new Heap<int>(Strategy.Max) {12, 2, 67, 90, 10};
Heap<int> expected = new Heap<int>(Strategy.Max) {12, 2, 67, 10};
Assert.IsTrue(actual.Remove(90));
CollectionAssert.AreEqual(expected, actual);
}
示例6: RemoveLastItemTest
public void RemoveLastItemTest()
{
Heap<int> actual = new Heap<int> {56, 23, 34, 1, 3};
Heap<int> expected = new Heap<int> {56, 34, 1, 3};
Assert.IsTrue(actual.Remove(23));
Assert.AreEqual(4, actual.Count);
CollectionAssert.AreEqual(expected, actual);
}
示例7: RemoveItemNotPresentTest
public void RemoveItemNotPresentTest()
{
Heap<int> actual = new Heap<int> {2, 78, 1, 0, 56};
Assert.IsFalse(actual.Remove(99));
}
示例8: FindPath
/// <summary>
/// Finds the shortest path from the start node to the goal node
/// </summary>
/// <param name="startPosition">Start position</param>
/// <param name="goalPosition">Goal position</param>
/// <param name="startMeshNode">Start mesh node</param>
/// <param name="goalMeshNode">Goal mesh node</param>
public List<NavmeshPolygon> FindPath(Vector3 startPosition, Vector3 goalPosition, NavmeshPolygon startPolygon, NavmeshPolygon goalPolygon)
{
//Debug.Log("AStar.FindPath");
//Debug.Log("startPosition == " + startPosition);
//Debug.Log("goalPosition == " + goalPosition);
StartPosition = startPosition;
GoalPosition = goalPosition;
GoalNode = new AStarNode(this, null, goalPolygon, 0);
StartNode = new AStarNode(this, null, startPolygon, 0);
Heap openList = new Heap();
Heap closedList = new Heap();
List<AStarNode> solution = new List<AStarNode>();
List<AStarNode> successors = new List<AStarNode>();
int printed = 0;
openList.Add(StartNode);
while (openList.Count > 0) {
//Debug.Log("AStar:main loop");
// Get the node with the lowest TotalSum
AStarNode nodeCurrent = (AStarNode)openList.Pop();
if (printed < 1000){
//Debug.Log("Current polygon: " + nodeCurrent.NavmeshPolygon.name + " - " + nodeCurrent.TotalCost);
printed++;
}
// If the node is the goal copy the path to the solution array
if (GoalNode.Equals(nodeCurrent)) {
//Debug.Log("AStar:finish loop");
while (nodeCurrent != null) {
solution.Insert(0, nodeCurrent);
nodeCurrent = nodeCurrent.Parent;
}
//convert solution
//Debug.Log("Path found");
return solution.ConvertAll(an => an.NavmeshPolygon);
}
// Get successors to the current node
successors.Clear();
nodeCurrent.GetSuccessors(successors);
foreach (AStarNode nodeSuccessor in successors) {
//Debug.Log("AStar:successor loop");
// Test if the currect successor node is on the open list, if it is and
// the TotalSum is higher, we will throw away the current successor.
//Debug.Log("AStarNode nodeOpen");
AStarNode nodeOpen;
if (openList.Contains(nodeSuccessor)) {
//Debug.Log("openList check: nodeSuccessor (" + nodeSuccessor.NavmeshPolygon.name + ") - " + nodeSuccessor.TotalCost);
//Debug.Log("openList contains nodeSuccessor");
//Debug.Log("nodeOpen = (AStarNode)openList[openList.IndexOf(nodeSuccessor)];");
nodeOpen = (AStarNode)openList.GetEqual(nodeSuccessor);
//Debug.Log("openList check: nodeOpen (" + nodeOpen.NavmeshPolygon.name + ") - " + nodeOpen.TotalCost);
//Debug.Log("if ((nodeOpen != null) && (nodeSuccessor.TotalCost > nodeOpen.TotalCost))");
if ((nodeOpen != null) && (nodeSuccessor.TotalCost > nodeOpen.TotalCost)){
//Debug.Log("continue;");
//Debug.Log("openList check: continued");
continue;
} else {
//Debug.Log("openList check: not continued");
}
}
// Test if the currect successor node is on the closed list, if it is and
// the TotalSum is higher, we will throw away the current successor.
//Debug.Log("AStarNode nodeClosed;");
AStarNode nodeClosed;
//Debug.Log("if (closedList.Contains(nodeSuccessor)) {");
if (closedList.Contains(nodeSuccessor)) {
//Debug.Log("closedList check: nodeSuccessor (" + nodeSuccessor.NavmeshPolygon.name + ") - " + nodeSuccessor.TotalCost);
//Debug.Log("closedList contains nodeSuccessor");
//Debug.Log("nodeClosed = (AStarNode)closedList[closedList.IndexOf(nodeSuccessor)];");
nodeClosed = (AStarNode)closedList.GetEqual(nodeSuccessor);
//Debug.Log("closedList check: nodeClosed (" + nodeClosed.NavmeshPolygon.name + ") - " + nodeClosed.TotalCost);
//Debug.Log("if ((nodeClosed != null) && (nodeSuccessor.TotalCost > nodeClosed.TotalCost))");
if ((nodeClosed != null) && (nodeSuccessor.TotalCost > nodeClosed.TotalCost)){
//Debug.Log("continue;");
continue;
}
}
// Remove the old successor from the open list
//Debug.Log("openList.Remove(nodeSuccessor);");
openList.Remove(nodeSuccessor);
// Remove the old successor from the closed list
//Debug.Log("closedList.Remove(nodeSuccessor);");
closedList.Remove(nodeSuccessor);
// Add the current successor to the open list
//.........这里部分代码省略.........
示例9: Remove_HeapWithOneElement
public void Remove_HeapWithOneElement()
{
Heap<int> heap = new Heap<int>(HeapType.Max)
{
List = new List<int>()
{
50
}
};
using (ShimsContext.Create())
{
bool heapifyDownCalled = false;
ShimHeap<int>.AllInstances.HeapifyDown = (h) => { heapifyDownCalled = true; };
Assert.AreEqual<int>(50, heap.Remove());
Assert.AreEqual<int>(0, heap.Count);
Assert.IsTrue(heapifyDownCalled);
}
}
示例10: Remove_MultipleBubbles
public void Remove_MultipleBubbles()
{
Heap<int> heap = new Heap<int>(HeapType.Max)
{
List = new List<int>()
{
50,
40,
30,
20,
10,
}
};
Assert.AreEqual<int>(50, heap.Remove());
Assert.AreEqual<int>(4, heap.Count);
Assert.AreEqual<int>(40, heap.List[0]);
Assert.AreEqual<int>(20, heap.List[1]);
Assert.AreEqual<int>(30, heap.List[2]);
Assert.AreEqual<int>(10, heap.List[3]);
}
示例11: Remove_SingleBubbleRightToLeaf
public void Remove_SingleBubbleRightToLeaf()
{
Heap<int> heap = new Heap<int>(HeapType.Max)
{
List = new List<int>()
{
50,
30,
40,
20,
}
};
Assert.AreEqual<int>(50, heap.Remove());
Assert.AreEqual<int>(3, heap.Count);
Assert.AreEqual<int>(40, heap.List[0]);
Assert.AreEqual<int>(30, heap.List[1]);
Assert.AreEqual<int>(20, heap.List[2]);
}
示例12: RemoveMaxHeapTest
public void RemoveMaxHeapTest([PexAssumeNotNull]int[] input)
{
//PexAssume.IsTrue(input.Length > 0);
PexAssume.AreDistinctValues<int>(input);
List<int> temp = new List<int>(input);
temp.Sort();
List<int> inputWithoutMax = new List<int>(input);
int max = temp.ToArray()[temp.Count-1];
inputWithoutMax.Remove(max);
Heap<int> actual = new Heap<int>(input, Strategy.Max);
Heap<int> expected = new Heap<int>(inputWithoutMax, Strategy.Max);
PexAssert.IsTrue(actual.Remove(max));
PexObserve.ValueForViewing<int[]>("Expected", expected.ToArray());
PexObserve.ValueForViewing<int[]>("Actual", actual.ToArray());
CollectionAssert.AreEquivalent(expected, actual);
}
示例13: RemoveItemPUT
public void RemoveItemPUT([PexAssumeNotNull]List<int> input, int randomPick)
{
//PexAssume.IsTrue(input.Contains(randomPick));
Heap<int> actual = new Heap<int> (input);
if (input.Contains(randomPick))
{
PexAssert.IsTrue(actual.Remove(randomPick));
PexAssert.AreEqual(input.Count - 1, actual.Count);
CollectionAssert.IsSubsetOf(actual, input);
}
else
{
PexAssert.IsFalse(actual.Remove(randomPick));
PexAssert.AreEqual(input.Count, actual.Count);
CollectionAssert.AreEquivalent(actual, input);
}
}