Domanda di colloquio di Bloomberg
unsorted integer array size n.
unmodifiable list of "less than" / "greater than" operators.
place elements from int array in between each "<" and ">" operator so that every comparison holds true.
e.g.
6, 2, 8, 1, 3, 9, 4, 0, 5, 7
<, >, <, <, <, >, <, >, >
answer:
0 < 9 > 1 < 2 < 3 < 8 > 4 < 7 > 6 > 5
Risposte di colloquio
Is this the same as a bubble sort, except you need to check each sign, instead of a universal one?
#include
using namespace std;
bool compare(int data[], const char* optrs, const int& sz) {
int temp;
for (int i = 0 ; i data[i+1]) {
temp = data[i];
data[i] = data[i+1];
data[i+1] = temp;
return false;
}
break;
case '>':
if (data[i] >";
int data[MAX_DATA_SIZE] = {6,2,8,1,3,9,4,0,5,7};
while(!compare(data, optrs, MAX_DATA_SIZE)) {
//Assuming the array data has a solution,
//Include code here to check for when there is no solution!
}
for (int i = 0 ; i < MAX_DATA_SIZE - 1 ; i++)
cout << data[i] << optrs[i];
cout << data[MAX_DATA_SIZE -1] << endl;
return 0;
}