Пример #1
0
        public void Add(Edge <VisVertex> edge)
        {
            if (IsEmpty)
            {
                head          = new AdjacencyVertexNode(edge);
                head.Previous = head;
                return;
            }
            if (edge <= head)
            {
                head = new AdjacencyVertexNode(edge, head.Previous, head);
                //При добавлении элемента в начало, сохраняем в начале указатель на конец
                head.Next.Previous = head;
                //Обновляем информацию о предшественнике у сдвинутого элемента
                return;
            }
            var currentNode = head;

            while (currentNode.Next != null && edge > currentNode.Next)
            {
                currentNode = currentNode.Next;
            }
            currentNode.Next = new AdjacencyVertexNode(edge, currentNode, currentNode.Next);
            if (currentNode.Next.Next == null)
            {
                head.Previous = currentNode.Next;
            }
            //Если добавили в конец, обновляем информацию о конце в Head
            else
            {
                currentNode.Next.Next.Previous = currentNode.Next;
            }
            //Если добавили не в конец,
            //обновляем информацию о предшественнике в элементе перед которым вставили
        }
Пример #2
0
        public Edge <VisVertex> ExtractMaxWeightEdge()
        {
            if (IsEmpty)
            {
                throw new Exception("Список пуст");
            }
            Edge <VisVertex> edge = head.Previous.Edge;

            if (head.Previous == head)
            {
                head = null;
            }
            else
            {
                head.Previous.Previous.Next = null;
                head.Previous = head.Previous.Previous;
            }
            return(edge);
        }
Пример #3
0
 public bool MoveNext()
 {
     if (list.IsEmpty)
     {
         return(false);
     }
     if (position == -1)
     {
         position++;
         return(true);
     }
     if (currentNode.HasNext)
     {
         currentNode = currentNode.Next;
         position++;
         return(true);
     }
     Reset();
     return(false);
 }
Пример #4
0
        public Edge <VisVertex> ExtractMinWeightEdge()
        {
            if (IsEmpty)
            {
                throw new Exception("Список пуст");
            }
            Edge <VisVertex> edge = head.Edge;

            if (head.Previous == head)
            {
                head = null;
            }
            else
            {
                var tmp = head.Previous;
                head          = head.Next;
                head.Previous = tmp;
            }
            return(edge);
        }
Пример #5
0
 public void Reset()
 {
     currentNode = list.Head;
     position    = -1;
 }
Пример #6
0
 public void Dispose()
 {
     list        = null;
     currentNode = null;
 }
Пример #7
0
 public AdjListEnumerator(AdjVertexSortedList list)
 {
     this.list   = list;
     currentNode = list.Head;
     position    = -1;
 }
Пример #8
0
 public AdjVertexSortedList()
 {
     head = null;
 }