Complete the constructor of class HouseList which is suppose
Solution
// constructor
public HouseList(){
// creating Dummy node
HouseListNode dummy = new HouseListNode();
dummy.Data= null; // storing \'null\' as House in dummy node of list
dummy.Next = null; // initially dummy node pointing to null
// initializing first and last node with dummy node
first = dummy;
last = dummy;
length = 0;
}
// Hi here you have not mentioned about the function that returns the Number of Rooms in a House (in side House Class)
// I am assuming that \'getNumOfRooms()\' is a method inside House class that returns the number of Rooms
public int countHouses(int numberOfRooms){
// list is empty
if(first.Next == null){
return 0;
}
HouseListNode temp = first.net; // getting first valid node of list
int countHouse = 0;
while(temp != null){
if(temp.Data.getNumOfRooms() == numberOfRooms)
countHouse++;
temp = temp.Next;
}
return countHouse;
}
