本文整理汇总了C#中System.Collections.Generic.PriorityQueue.Dequeue方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.Dequeue方法的具体用法?C# PriorityQueue.Dequeue怎么用?C# PriorityQueue.Dequeue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic.PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.Dequeue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: makeNextMove
public int[] makeNextMove(Grid board)
{
PriorityQueue<MoveNode> q = new PriorityQueue<MoveNode>();
q.initialize(expandNodes(board, null, 1));
MoveNode current = q.Dequeue();
while ((current.Ply < depth) && !(q.isEmpty))
{
MoveNode next = q.Dequeue();
if(next.Rank> current.Rank)
{
current = next;
MoveNode[] expnd = expandNodes(current.Board, current, (current.Ply + 1));
if(expnd.Length > 0)
q.EnqueueArray(expnd);
}
}
while(current.Ply > 1)
{
current = current.PreviousMove;
}
//this will be the best move to make after expanding down to depth plys.
int[] result = { current.Group.X, current.Group.Y };
Console.WriteLine("rank: " + current.Rank);
return result;
}
示例2: TestBasicFunctionality
public void TestBasicFunctionality()
{
var q = new PriorityQueue<int>();
Assert.AreEqual(0, q.Count);
Assert.AreEqual(0, q.Capacity);
Assert.Throws<InvalidOperationException>(() => q.Peek());
Assert.Throws<InvalidOperationException>(() => q.Dequeue());
q.Enqueue(5);
q.Enqueue(2);
q.Enqueue(4);
Assert.AreEqual(3, q.Count);
Assert.IsTrue(q.Capacity >= 3);
Assert.IsTrue(q.Contains(2));
Assert.IsFalse(q.Contains(3));
Assert.AreEqual(3, q.ToArray().Length);
CollectionAssert.AreEqual(q.ToArray(), q);
Assert.AreEqual(2, q.Peek());
Assert.AreEqual(2, q.Dequeue());
Assert.AreEqual(4, q.Dequeue());
Assert.AreEqual(5, q.Dequeue());
}
示例3: Remove
public void Remove()
{
PriorityQueue<int> p = new PriorityQueue<int>(delegate(int i, int j) { return i - j; });
Random r = new Random();
for(int i = 0; i < 10000; ++i) {
p.Enqueue(r.Next(1000));
}
int removed = 0;
while(removed < 100) {
int count = p.Count;
p.Remove(r.Next(1000));
if(count > p.Count) {
++removed;
}
}
int item = p.Dequeue();
while(p.Count > 0) {
int next = p.Dequeue();
if(next < item) {
Assert.Fail("bad order detected");
}
}
}
示例4: Main
static void Main(string[] args)
{
var queue = new PriorityQueue<int>();
queue.Enqueue(5);
queue.Enqueue(8);
queue.Enqueue(3);
queue.Enqueue(4);
queue.Enqueue(11);
foreach (var i in queue)
{
Console.WriteLine(i);
}
Console.WriteLine("*******Removed value:{0}",queue.Dequeue());
foreach (var i in queue)
{
Console.WriteLine(i);
}
Console.WriteLine("*******Removed value:{0}", queue.Dequeue());
foreach (var i in queue)
{
Console.WriteLine(i);
}
}
示例5: Main
public static void Main()
{
// 1.
var priorityQueue = new PriorityQueue<int>();
priorityQueue.Enqueue(2);
priorityQueue.Enqueue(7);
priorityQueue.Enqueue(17);
priorityQueue.Enqueue(19);
priorityQueue.Enqueue(26);
priorityQueue.Enqueue(29);
priorityQueue.Dequeue();
priorityQueue.Enqueue(3);
priorityQueue.Enqueue(1);
priorityQueue.Dequeue();
priorityQueue.Enqueue(25);
priorityQueue.Enqueue(36);
priorityQueue.Dequeue();
Console.WriteLine();
// 2.
PrintFirst20Products();
Console.WriteLine();
// 3.
CountWords();
}
示例6: PriorityQueue
public void PriorityQueue()
{
PriorityQueue<int> pq = new PriorityQueue<int>(LinqExt.TakeMore);
pq.Enqueue(1, 1);
pq.Enqueue(9, 9);
pq.Enqueue(2, 2);
pq.Enqueue(5, 5);
Assert.IsTrue(pq.First() == 9, "Wrong Priority");
Assert.IsTrue(pq.Dequeue() == 9, "Wrong Priority");
Assert.IsTrue(pq.Dequeue() == 5, "Wrong Priority");
pq.ChangePriority(1, 29);
Assert.IsTrue(pq.First() == 1, "Wrong Priority, 1 should be first priority now with priority 29");
pq.Enqueue(3, 2); //add item with same priority
pq.Enqueue(4, 2); //add item with same priority
Assert.IsTrue(pq.Last() == 4, "Wrong Priority, 4 should be last");
pq.Enqueue(30, 30); // mix case
Assert.IsTrue(pq.First() == 30, "Wrong Priority, 30 should be first priority");
pq.Enqueue(31, 30); // mix case
Assert.IsTrue(pq.First() == 30, "Wrong Priority, 30 should still be first priority");
pq.Enqueue(5, 2); //add item with same priority
pq.Enqueue(6, 2); //add item with same priority
Assert.IsTrue(pq.Last() == 6, "Wrong Priority, 6 should be last");
}
示例7: OnTick
public async void OnTick(IWeiboAccessToken at)
{
if (_tick++%57 != 0)
return;
var resp = await WeiboClient.suggestions_statuses_hot_async(at.get(), 20, true, 1, _type);
if(++_type == hot_status_type.count)
_type = hot_status_type.musement;
if (resp.Failed() || resp.Value.Length == 0)
return;
var queue = new PriorityQueue<long, Status>();
foreach(var s in resp.Value)
{
queue.Enqueue(EvalMark(s),s);
}
while (queue.Size > 5)
queue.Dequeue();
while(!queue.IsEmpty)
{
var s = queue.Dequeue();
var ws = new WeiboStatus();
ws.assign_sina(s);
await DispatcherHelper.UIDispatcher.BeginInvoke(DispatcherPriority.SystemIdle, (Action) (() =>
{
if(statuses.Count > 10)
statuses.RemoveAt(0);
statuses.Add(ws);
}));
}
}
示例8: EnqDeq
public void EnqDeq()
{
var pq = new PriorityQueue<string>();
pq.Enqueue(1, "world");
pq.Enqueue(2, "hello");
Assert.AreEqual("hello", pq.Dequeue());
Assert.AreEqual("world", pq.Dequeue());
}
示例9: ConstructFromSequence
public void ConstructFromSequence()
{
var pq = new PriorityQueue<int>(new int[] { 1, 4, 2, 10, -10 });
Assert.AreEqual(-10, pq.Dequeue());
Assert.AreEqual(1, pq.Dequeue());
Assert.AreEqual(2, pq.Dequeue());
Assert.AreEqual(4, pq.Dequeue());
Assert.AreEqual(10, pq.Dequeue());
}
示例10: TestOrder
public void TestOrder()
{
PriorityQueue<int, string> q = new PriorityQueue<int, string>();
q.Enqueue(0, "a");
q.Enqueue(-1, "b");
q.Enqueue(1, "c");
Assert.AreEqual("b", q.Dequeue());
Assert.AreEqual("a", q.Dequeue());
Assert.AreEqual("c", q.Dequeue());
q.Enqueue(0, "a");
q.Enqueue(0, "b");
q.Enqueue(0, "c");
q.Enqueue(1, "c");
q.Enqueue(1, "d");
q.Enqueue(1, "e");
Assert.AreEqual("a", q.Dequeue());
Assert.AreEqual("b", q.Dequeue());
Assert.AreEqual("c", q.Dequeue());
Assert.AreEqual("c", q.Dequeue());
Assert.AreEqual("d", q.Dequeue());
Assert.AreEqual("e", q.Dequeue());
}
示例11: TestConstructWithComparer
public void TestConstructWithComparer()
{
var q = new PriorityQueue<int>(Comparer<int>.Create((a, b) => -a.CompareTo(b)));
q.Enqueue(5);
q.Enqueue(2);
q.Enqueue(4);
Assert.AreEqual(5, q.Dequeue());
Assert.AreEqual(4, q.Dequeue());
Assert.AreEqual(2, q.Dequeue());
}
示例12: New_highest_prio_is_added_at_head
public void New_highest_prio_is_added_at_head()
{
var sut = new PriorityQueue<string>();
sut.Enqueue("0");
sut.Enqueue(1, "1");
sut.Enqueue(2, "2");
Assert.AreEqual("2", sut.Dequeue());
Assert.AreEqual("1", sut.Dequeue());
Assert.AreEqual("0", sut.Dequeue());
}
示例13: BasicTest
public void BasicTest()
{
var pq = new PriorityQueue<int>();
pq.Enqueue(5);
pq.Enqueue(3);
pq.Enqueue(10);
pq.Enqueue(1);
Assert.AreEqual(1, pq.Dequeue());
Assert.AreEqual(3, pq.Dequeue());
Assert.AreEqual(5, pq.Dequeue());
Assert.AreEqual(10, pq.Dequeue());
}
示例14: CustomComparer
public void CustomComparer()
{
var pq = new PriorityQueue<int>(
(lhs, rhs) => (10 - lhs).CompareTo(10 - rhs)
);
pq.Enqueue(5);
pq.Enqueue(3);
pq.Enqueue(10);
pq.Enqueue(1);
Assert.AreEqual(10, pq.Dequeue());
Assert.AreEqual(5, pq.Dequeue());
Assert.AreEqual(3, pq.Dequeue());
Assert.AreEqual(1, pq.Dequeue());
}
示例15: Main
static void Main(string[] args)
{
PriorityQueue<int> heap = new PriorityQueue<int>();
heap.Enqueue(1);
heap.Enqueue(2);
heap.Enqueue(3);
heap.Enqueue(4);
heap.Dequeue();
heap.Enqueue(3);
heap.Enqueue(5);
Console.WriteLine(heap.Dequeue());
heap.ToString();
heap.Enqueue(2);
heap.ToString();
}