Question
Please fix constructHeap() function in my code // Title: heap.cpp #include #include #include using namespace std; bool checkForHeap(vector nums) { for (int i = 0;
Please fix constructHeap() function in my code
// Title: heap.cpp #include
bool checkForHeap(vector
void constructHeap(vector
for (int num : nums) { cout << num << " "; } }
int main() { int user_size, user_choice; vector
for (int i = 0; i < user_size; i++) { int num; cin >> num; nums.push_back(num); }
if (!checkForHeap(nums)) { cout << "This is NOT a heap." << endl; cout << "Heap constructed: "; constructHeap(nums); cout << endl; cout << "Select an operation" << endl; cout << " 1. Insert a number" << endl; cout << " 2. Delete the max" << endl; cout << " 3. Heapsort & Quit" << endl; cin >> user_choice; while (user_choice == 1 || user_choice == 2 || user_choice == 3) { if (user_choice == 1) { cout << "Enter a number: "; int insert_num; cin >> insert_num; nums.push_back(insert_num); for (int i = 0; i < nums.size(); i++) { cout << nums[i] << " "; } cout << endl; cout << "Updated heap: "; constructHeap(nums); } /*else if (user_choice == 2) {
} else if (user_choice == 3) {
}*/ cout << "Select an operation" << endl; cout << " 1. Insert a number" << endl; cout << " 2. Delete the max" << endl; cout << " 3. Heapsort & Quit" << endl; cin >> user_choice; } } else { cout << "This is a heap." << endl; cout << "Select an operation" << endl; cout << " 1. Insert a number" << endl; cout << " 2. Delete the max" << endl; cout << " 3. Heapsort & Quit" << endl; // cin >> user_choice; // while (user_choice == 1 || user_choice == 2 || user_choice == 3) { // if (user_choice == 1) {
// } else if (user_choice == 2) {
// } else if (user_choice == 3) {
// } // cout << "Select an operation" << endl; // cout << " 1. Insert a number" << endl; // cout << " 2. Delete the max" << endl; // cout << " 3. Heapsort & Quit" << endl; // cin >> user_choice; // } }
system("pause"); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started