Hello! I need help with these questions relating to c++

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Hello! I need help with these questions relating to c++

Post by answerhappygod »

Hello! I need help with these questions relating to c++
Hello I Need Help With These Questions Relating To C 1
Hello I Need Help With These Questions Relating To C 1 (28.98 KiB) Viewed 60 times
Hello I Need Help With These Questions Relating To C 2
Hello I Need Help With These Questions Relating To C 2 (22.36 KiB) Viewed 60 times
Question 26 1 pts What, if anything, is wrong with the MaxHeap class template below? template<typename T> class Махнеар { public: MaxHeap(); void push(T element); I top() const; void pop(); int size() const; private: int get_left_child_index(int index) const; int get_right_child_index(int index) const; int get_parent_index(int index) const; I get_left_child(int index) const; I get_right_child(int index) const; I get_parent(int index) const; vector<T> elements; }; All the functions should be public; only the elements vector should be private. It is missing the fix_heap() function. It is missing the insert(T element) function. The class template has no errors.

Question 27 1 pts Suppose after turning an array into a heap, it is 9 4 5 13. What is the array after the first iteration of the while loop in the heap_sortfunction? void heap_sort(int a[], int size) { int n = size - 1; for (int i = (n - 1) / 2; i >= 0; i--) { fix_heap(a, i, n); //convert subarrays to heaps } while (n > @) { int temp = a[@]; // Swap root a[e] a[n]; a[n] = temp; n--; fix_heap(a, e, n); //convert back to a heap } } 94531 54319 54139 13459
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply