Given the following code:
public void expand(Object a) {
// assume element has enough capacity
for (int i = size - 1; i >= 0; i--) {
element[4 * i + 3] = a;
element[4 * i + 2] = a;
element[4 * i + 1] = a;
element[4 * i] = element[i];
}
size = 4 * size;
}
element is a one-dimensional array that stores elements of the type Object. The data
member size is such that the list elements are in positions 0 through size-1 of the array.
(a)If the list element[0:2] = [a, b, c], whose size is 3, write the result and the size of the array element after executing
expand(new Integer(d)).
Assume that the array element has enough capacity for expansion.
where a, b, c, d are generated as follow:
Number |
Based on your student ID number, formed by its |
a |
1 st and 2nd digits |
b |
2 nd and 3rd digits |
c |
3 rd and 4th digits |
d |
4 th and 5th digits |
For example, the student ID is 19563755A.
Values of a to d are: 19, 95, 56, 63
expand(object a) OUTPUT
:
element[4*2+3] = element[11] = a;
element[4*2+2] = element[10] = a;
element[4*2+1] = element[9] = a;
element[4 * 2] = element[2] = c;(given)
similarly,
element[11] = a;
element[10] = a;
element[9] = a;
element[8] = c;
element[7] = a;
element[6] = a;
element[5] = a;
element[4] = b;
element[3] = a;
element[2] = a;
element[1] = a;
element[0] = a;
size = 4*3 = 12;
CODE FOR SECOND PART
public void expand(new integer d){
string str;
cin>>str;
int size = str.length();
int input[size];
for(int i=0; str[i]!='\0'; i++){
input[i] =
str[i]-'0';
}
int a, b, c, d;
a = input[0]*10 + input[1];
b = input[1]*10 + input[2];
c = input[2]*10 + input[3];
d = input[3]*10 + input[4];
}
Get Answers For Free
Most questions answered within 1 hours.