Exemplo n.º 1
0
        public void Remove(DataType dt)
        {
            bool         found = false;
            PriorityType pt    = default(PriorityType);

            foreach (var List in Priorities)
            {
                if (List.Value.Contains(dt))
                {
                    if (List.Value.Remove(dt))
                    {
                        found = true;
                        if (List.Value.Count == 0)
                        {
                            pt = List.Key;
                        }
                        break;
                    }
                    else
                    {
                        throw new Exception("PQ Value Remove Failed");
                    }
                }
                else
                {
                    continue;
                }
            }
            if (!found)
            {
                throw new InvalidOperationException(
                          "Priority Queue Does Not Contain " + dt);
            }
            else
            {
                if (pt != null)
                {
                    if (!Priorities.ContainsKey(pt))
                    {
                        System.Console.WriteLine("PQ Priority Remove Will Fail");
                    }

                    if (!Priorities.Keys.ToArray( ).Contains(pt))
                    {
                        System.Console.WriteLine("PQ Priority Remove Will Fail");
                    }
                    if (!Priorities.Remove(pt))
                    {
                        throw new Exception("PQ Priority Remove Failed");
                    }
                }
            }
        }