void Start() { pq = new Heap(); pq.BuildMinHeap(); GameObject[] t = GameObject.FindGameObjectsWithTag("Waypoint"); Vertexes = new ArrayList(); int j = 0; foreach (var g in t) { Vertex tmp = new Vertex(); tmp.position = g.transform.position; tmp.val = Vector2.SqrMagnitude(tmp.position - (Vector2)transform.position); pq.Insert(tmp); Debug.Log(tmp.ToString()); j++; } Vertex tmp1 = new Vertex(); tmp1.position = transform.position; tmp1.val = 0; pq.Insert(tmp1); Debug.Log("Output"); for (int i = 0; i <= j; i++) { Debug.Log(pq.ExtractMin().val); } }
public void Input() { List <int> _runs = new List <int>(); Heap _heap = new Heap(); int n = Convert.ToInt32(Console.ReadLine()); int[][] runsArray = new int[3][]; for (int i = 0; i < 3; i++) { string[] runs = Console.ReadLine().Split(' '); runsArray[i] = new int[n]; for (int j = 0; j < n; j++) { runsArray[i][j] = Convert.ToInt32(runs[j]); } } for (int i = 0; i < n; i++) { _runs.Add(runsArray[0][i] + runsArray[1][i] + runsArray[2][i]); } _heap.BuildMinHeap(_runs); int q = Convert.ToInt32(Console.ReadLine()); while (q > 0) { q--; int k = Convert.ToInt32(Console.ReadLine()); if (k > _runs.Count) { Console.WriteLine(-1); continue; } List <int> deletedRuns = new List <int>(); while (k > 1) { deletedRuns.Add(_heap.ExtractMin(_runs)); k--; } Console.WriteLine(_heap.ExtractMin(_runs)); _runs.AddRange(deletedRuns); _heap.BuildMinHeap(_runs); } }
private void Push(int n) { if (_arrCnt.ContainsKey(n)) { _arrCnt[n]++; } else { _arrCnt.Add(n, 1); _arrMaxHeap.Add(n); _arrMinHeap.Add(n); _heap.BuildMaxHeap(_arrMaxHeap); _heap.BuildMinHeap(_arrMinHeap); } }
public PriorityQueue(IEnumerable <T> data, PriorityOrder order) { _data = data as IList <T>; if (_data == null) { _data = new List <T>(data); } _order = order; _heapSize = _data.Count; if (_order == PriorityOrder.Max) { Heap.BuildMaxHeap(_data); } else { Heap.BuildMinHeap(_data); } }