Example #1
0
        public void ElementAndPriorityAt(int i, out T element, out int priority)
        {
            ElementPriorityPair <T> elementPriorityPair = _list[i];

            element  = elementPriorityPair.Element;
            priority = elementPriorityPair.Priority;
        }
Example #2
0
        public void Add(T element, int priority)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element", "The element can't be null.");
            }
            LinkedListNode <ElementPriorityPair <T> > linkedListNode = _list.First;
            ElementPriorityPair <T> value = new ElementPriorityPair <T>(element, priority);

            while (linkedListNode != null)
            {
                if (priority > linkedListNode.Value.Priority)
                {
                    _list.AddBefore(linkedListNode, value);
                    return;
                }
                linkedListNode = linkedListNode.Next;
            }
            _list.AddLast(value);
        }
Example #3
0
        public int Add(T element, int priority)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element", "The element can't be null.");
            }
            int i = 0;

            for (int count = _list.Count; i < count; i++)
            {
                ElementPriorityPair <T> elementPriorityPair = _list[i];
                if (object.ReferenceEquals(elementPriorityPair.Element, element))
                {
                    return(-1);
                }
                if (priority > elementPriorityPair.Priority)
                {
                    _list.Insert(i, new ElementPriorityPair <T>(element, priority));
                    return(i);
                }
            }
            _list.Add(new ElementPriorityPair <T>(element, priority));
            return(_list.Count - 1);
        }