Exercices about collections

For all methods, you will write JUnit tests.

Exercice 1

Exercice 2

Question 1

We create a SocialUser class. Each SocialUser has a name, and a set of friends (who are themselves SocialUsers). Propose an implementation. It should have a addFriend() method. Note that we suppose that if x is a friend of y, then y is a friend of x.

Question 2

A relation is a friend, or a friend of a friend, etc... more precisely, friends are relations, and relations of friends are also relations. Try to use the following algorithm to implements a getRelation() method:

    e= current social user
	stack= empty stack
	seen= empty set
	
	push e.friends on stack
	add e to seen
	while stack is not empty:
		e1= stack.pop()
		if (seen does not contain e1) 
		    add e1 to seen
			push e1.friends on stack
		end if
	end while
	// now, seen contains all the relations of e.