#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(); } } }
时间: 2024-10-24 15:51:35