public void Add(T key, K value) { MapNode <T, K> newNode = new MapNode <T, K>(key, value); if (count == 0) { list.AddLast(newNode); list.First().GetItem().Add(value); } else { // find the node that belongs to the key MapNode <T, K> cur = null; foreach (MapNode <T, K> n in list) { if (key.Equals(n.GetKey())) { cur = n; break; } } if (cur == null) { // key does not exist list.AddLast(newNode); } else { // we have the node, insert the value last cur.Add(value); } } count++; }