首页 > 代码库 > C#使用PriorityQueue

C#使用PriorityQueue

 

#pragma once
#include<cliext/queue>
#include<cliext/vector>
using namespace cliext;
using namespace System;
using namespace Microsoft::VisualC::StlClr;
namespace ClassLibrary2
{
    public ref class Class1
    {
    public:
        static IPriorityQueue<Object ^, IVector<Object ^> ^> ^PriorityQueue(priority_queue<Object ^>::value_compare ^comp)
        {
            return gcnew priority_queue<Object ^>(comp);
        }
    };
}

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static ClassLibrary2.Class1;
using Microsoft.VisualC.StlClr;

namespace ConsoleApplication2
{
    class Program
    {
        static bool comp1(object o1,object o2)
        {
            return (int)o1 < (int)o2;
        }
        static void Main(string[] args)
        {
            Random rnd = new Random();
            IPriorityQueue<object, IVector<object>> IPri = PriorityQueue(comp1);
            for (int i = 0; i < 10; i++)
                IPri.push(rnd.Next());
            for(int i=0;i<10;i++)
            {
                Console.Write(IPri.top_item.ToString() + " ");
                IPri.pop();
            }
            Console.ReadKey();
        }
    }
}

 

C#使用PriorityQueue