x****3 发帖数: 5 | 1 Here is the question
Question1:
An array is being used to represent an organizational hierarchy. This is
done by using the array subscript to map to the employee-id and the value in
each element to represent the employee-id of the supervisor of the employee
.
For example the first element in the array maps to the supervisor of
employee-id 1, the second element maps to the supervisor of employee id 2.
The corresponding value for the top person in the organization is set to -1.
For example the f | x****3 发帖数: 5 | 2 Here is the solution I come out, any suggestions. Thanks a lot!
int[] employees= new Array[N]
int topid=0;
private List getListofEmployee(int level)
{
if(level==1)
{
List temp=new ArrayList();
for(int i=0; i
{
if(employees[i]==-1)
topid=i+1;
}
for(int i=0; i
{
if(employees[i]=topid)
temp.add(i);
}
return temp;
}else{
List temp=getListofEmployee(level-1);
List temp1=new ArrayList();
for(int i=0; i
|
|