PLEASE PROVIDE A PSEUDOCODE FOR THE C++ SOURCE CODE BELOW #include <iostream> us
ID: 3744427 • Letter: P
Question
PLEASE PROVIDE A PSEUDOCODE FOR THE C++ SOURCE CODE BELOW #include <iostream> using namespace std; int* ExpandArray(int data[], int size) { int *arr = new int[2*size]; for(int i = 0; i < 2*size; ++i) { if(i < size) { arr[i] = data[i]; } else { arr[i] = 0; } } return arr; } int main() { int size = 2; int* values = new int[size]; values[0] = 55; values[1] = 77; for (int index = 0; index < size; index++) { cout << values[index] << endl; } values = ExpandArray(values, size); for (int index = 0; index < size * 2; index++) { cout << values[index] << endl; } delete[] values; return 0; }
Explanation / Answer
function ExpandArray(data)
BEGIN
// create a new array of double the capacity of the array arr
arr = new array of size 2 * data.size()
// traverse the array arr
for i = 1 to arr.size()
BEGIN
If I < arr.size()
BEGIN
arr[i] = date[i]
Else
arr[i] = 0
END
END
return arr
END
Function main()
BEGIN
values = create a new array of size size
values[0] = 55
values[1] = 77
for i = 1 to size
BEGIN
Print( values[index] )
END
values = ExpandArray(values, size)
for i = 1 to values.size()
BEGIN
Print( values[index] )
END
delete values
END
in words
Funciton expandArray( data )
Function main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.