Beispiel #1
0
 public void AddPanda(Panda panda)
 {
     if(container.ContainsKey(panda))
     {
         throw 
     }
 }
        public int ConnectionLevel ( Panda p1 , Panda p2 )
        {
            Queue<Panda> qP = new Queue<Panda>();
            Queue<int> qL = new Queue<int>();
            HashSet<Panda> S = new HashSet<Panda>();
            qP.Enqueue(p1);
            qL.Enqueue(0);
            S.Add(p1);

            while(qP.Count > 0)
            {
                Panda p = qP.Dequeue();
                int level = qL.Dequeue();
                if(p.Equals(p2))
                    return level;
                foreach(Panda friend in p.Friends)
                {
                    if(!S.Contains(friend))
                    {
                        qP.Enqueue(friend);
                        qL.Enqueue(level + 1);
                        S.Add(friend);
                    }
                }
            }
            return -1;
        }
Beispiel #3
0
        public PandaSocialNetwork(Panda newPanda)
        {
            if (pandaList.Contains(newPanda))
	        {
		        throw new Exception("Panda already there!");
	        }
            else
	        {
                pandaList.Add(newPanda);
	        }          
        }
Beispiel #4
0
 private bool HasPanda(Panda isSocial)
 {
     if (pandaList.Contains(isSocial))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
 static void Main ( string[] args )
 {
     Panda p = new Panda("Ivan" , "*****@*****.**" , Gender.male);
     Panda p2 = new Panda("Gosho" , "*****@*****.**" , Gender.male);
     Panda p3 = new Panda("Maria" , "*****@*****.**" , Gender.female);
     Panda p1 = new Panda("Lorna" , "*****@*****.**" , Gender.female);
     PandaSocialNetwork net = new PandaSocialNetwork();
     net.Users.AddRange(new Panda[] { p , p2 , p3, p1 });
     net.MakeFriends(p , p2);
     net.MakeFriends(p2 , p3);
     net.MakeFriends(p2 , p1);
     net.MakeFriends(p3 , p1);
     Console.WriteLine( net.ConnectionLevel(p , p3));
     Console.WriteLine(net.ConnectionLevel(p , p));
     Console.WriteLine(net.ConnectionLevel(p , p2));
     Console.WriteLine(net.ConnectionLevel(p , p1));
 }
Beispiel #6
0
        private void MakeFriends(Panda panda1, Panda panda2)
        {
            if (!pandaList.Contains(panda1))
            {
                pandaList.Add(panda1);
            }

            if (!pandaList.Contains(panda2))
            {
                pandaList.Add(panda2);
            }

            if (!pandaFriendList.ContainsKey(panda1))
            {
                pandaFriendList.Add(panda1, new List<Panda>());
            }

            if (pandaFriendList[panda1].Contains(panda2))
            {
                throw new PandasAlreadyFriendsException(panda1, panda2);
            }

            pandaFriendList[panda1].Add(panda2);
        }
Beispiel #7
0
 public bool AreConnected(Panda p1, Panda p2)
 {
     return true;
 }
Beispiel #8
0
 public PandaNode(Panda p )
 {
     Accounter = p;
 }
 public Panda(Panda p): this(p.Name, p.Mail, p.Gender)
 {
     friends = new List<Panda>(p.friends);
 }
 public PandasAlreadyFriendsException(Panda panda1, Panda panda2)
 {
     Panda1 = panda1;
     Panda2 = panda2;
 }
 public bool AreConnected ( Panda p1 , Panda p2 )
 {
     return ConnectionLevel(p1 , p2) != 0;
 }
 public List<Panda> FriendsOf ( Panda p )
 {
     return p.Friends;
 }
 public bool AreFriends ( Panda p1 , Panda p2 )
 {
     return p1.Friends.Contains(p2) && p2.Friends.Contains(p1);
 }
 public void MakeFriends ( Panda p1 , Panda p2 )
 {
     p1.Friends.Add(p2);
     p2.Friends.Add(p1);
 }
 public bool HasPanda ( Panda p )
 {
     return users.Contains(p);
 }
 public void AddPanda ( Panda p )
 {
     users.Add(p);
 }