Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ Please explain why its wrong. The findDisorder function is supposed to find the first item in an array that is less than the element

c++ Please explain why its wrong.

The findDisorder function is supposed to find the first item in an array that is less than the element preceding it, and set the p parameter to point to that item, so the caller can know the location of that item. Explain why this function won't do that, and show how to fix it. Your fix must be to the function only; you must not change the the main routine below in any way, yet as a result of your fixing the function, the main routine below must work correctly. void findDisorder(int arr[], int n, int* p) { for (int k = 1; k < n; k++) { if (arr[k] < arr[k-1]) { p = arr + k; return; } } p = nullptr; } int main() { int nums[6] = { 10, 20, 20, 40, 30, 50 }; int* ptr; findDisorder(nums, 6, ptr); if (ptr == nullptr) cout << "The array is ordered" << endl; else { cout << "The disorder is at address " << ptr << endl; cout << "It's at index " << ptr - nums << endl; cout << "The item's value is " << *ptr << endl; } return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions

Question

Describe the seven standard parts of a letter.

Answered: 1 week ago

Question

Explain how to develop effective Internet-based messages.

Answered: 1 week ago

Question

Identify the advantages and disadvantages of written messages.

Answered: 1 week ago