Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2 (6 marks) Use C/C++ to answer this question. Suppose that A points to an array of positive integers. In order to tell the end

image text in transcribed

2 (6 marks) Use C/C++ to answer this question. Suppose that A points to an array of positive integers. In order to tell the end of the array, the last element of the array is always -1. Create a function called int *searchArray(int * A, int x), which searches in A for the occurrences of number x. Each time you call the function, it returns a pointer to the next position of x in the array, if x appears next. Or it returns nullptr. For the first call to searchArray, you need to pass in A and x. But for any subsequent calls you only need to pass in A and -1. As an example, suppose that A points to the following array: subscript element 0 10 1 30 2 40 3 50 4 40 5 60 6 50 7 40 8 30 9 20 10 -1 We can call the function searchArray as follows to see the number of 40s in the array. (Of course, this is only for illustration purpose. We can do many other potential operations using this function, such as processing the numbers between two 40s in the array.) int *pos; int count = 0; pos = searchArray(A, 40); while (pos != nullptr) { cout

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

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions

Question

3. How do you get past Robins defensiveness?

Answered: 1 week ago

Question

5. Who should facilitate the focus group?

Answered: 1 week ago