0
public class hia
{

    String name;
    public ArrayList<hia> subordonat=new ArrayList<>();

    public hia(String name)
    {
        this.name=name;
    }

    public void add(hia e)
    {
        subordonat.add(e);
    }

    public void print() {
        System.out.println(name);
        for (hia e : subordonat)
        {
            e.print();
        }
    }

    public void delete()
    {
        for(hia e:subordonat)
        {
            if(name=="Unavailable")
            {

            }
        }
    }
    
}

So, my main problem is that I made this tree that's suppose to emulate the hierarchy of a company (like any employee has an n number of subordinates that he manages, and those also have subordinates, and so on) and what I have to make is a function that will delete any employee that has his name as "unavailable," along with all his subordinates.

However, I haven't worked much on trees and I don t really know what to do.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • 1
    [How do I compare Strings in Java?](https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – maloomeister Dec 17 '20 at 10:58
  • And in the `delete` method, reverses the if and the for. Unless `name` is the `name` of `e`, then replaces `name` with `e.name`. – Redoishi Dec 17 '20 at 11:12
  • @Redsarow why would i replace name with e.name? – Halil Simionca Dec 17 '20 at 11:47
  • I probably misspoke. The position of the `if` in the `for` suggests that you want to test the name of `e`. Hence my suggestion for replacement. – Redoishi Dec 17 '20 at 15:05
  • @Redsarow i did that, should i now just call a function to delete a name and that s it ? – Halil Simionca Dec 17 '20 at 20:03
  • If the goal is to remove anyone with the name `Unavailable` from the list of subordinates. It is then sufficient to delete the member `e` of `subordonat`. Please note that it is not possible to navigate in a list and delete an element at the same time. You will have to duplicate the `subordonate` list to use it in the `for`. – Redoishi Dec 18 '20 at 08:36

0 Answers0