#pragma once template class priorityQueue{ private: int capacity; int index; int numItems; TYPE_ * arr; void sortTheArr(){ for(int x = 0 ; x< capacity; x++){ int smallest = arr[x]; int index = x ; for(int y = x; y < capacity; y++){ if(arr[y] < smallest){ smallest = arr[y]; index = y; } TYPE_ temp = arr[index]; arr[index] = smallest; } } } void resize(int newCap){ TYPE_ * arr2 = new TYPE_[newCap]; for(int x = 0; x < capacity; x++){ arr2[x] = arr[x]; } delete[] arr; arr = arr2; capacity = newCap; } public: priorityQueue(){ capacity = 10; index = 0; numItems = 0; arr = new TYPE_[capacity]; } void insert(TYPE_ item){ numItems++; if(numItems == capacity){ resize(capacity * 2); } else{ //cout<< "inserting "<< item << " into "<< index< #include "priorityQueue.h" using namespace std; template void priorityQueueSort(THING * items, int start, int end) { //declare a variable of type priority queue priorityQueue p1; //insert the items from the 'items' array into the priority queue, one by one for(int x = start; x < end+1; x++){ p1.insert(items[x]); cout << "adding "<< items[x]<< " into "<< x< pq; pq.insert(57); pq.insert(32); pq.insert(105); pq.insert(17); cout << pq.extractMin() << endl; //17 cout << pq.extractMin() << endl; //32 cout << endl; pq.insert(68); pq.insert(5); pq.insert(43); cout << pq.extractMin() << endl; //5 cout << pq.extractMin() << endl; //43 cout << pq.extractMin() << endl; //57 cout << endl; pq.insert(120); pq.insert(500); pq.insert(3); pq.insert(73); pq.insert(29); //3 29 68 73 105 120 500 while (!pq.empty()) { cout << pq.extractMin() << endl; } cout << endl; /////////////////////////////////////////////////////////////////// //Step 2: now, write a sorting routine that uses a priority queue to sort /////////////////////////////////////////////////////////////////// //fill a big array with random numbers int size = 10; int * numbers = new int[size]; for (int i = 0; i < size; i++) { //numbers[i] = rand(); numbers[i] = i *i; cout << "original " << numbers[i] << endl; } //sort the array using a priority queue to help you priorityQueueSort(numbers, 0, size - 1); //now array should be in sorted order for (int i = 0; i < size; i++) { cout << "sorted "; cout << numbers[i] << endl; } return 0; }