Пример #1
0
 public void NextWeapon()
 {
     if (currentWeaponIndex.Equals(availableWeapons.Last))
     {
         currentWeaponIndex = availableWeapons.First;
     }
     else
     {
         currentWeaponIndex = currentWeaponIndex.Next;
     }
     RenderCurrentWeapon();
 }
Пример #2
0
 private void UndoPerson()
 {
     if (CurrentNode.Equals(PersonList.First))
     {
         Console.WriteLine();
         Console.WriteLine("It is the first modification. Press any key to continue");
         Console.ReadKey();
     }
     else
     {
         CurrentNode = CurrentNode.Previous;
     }
 }
Пример #3
0
        public bool RemoveCustomerFromContract(int customerID, int contractID)
        {
            LinkedListNode <Customer> customerTemp = _customersList.First;
            LinkedListNode <Contract> contractTemp = _contractList.First;

            while (!customerTemp.Equals(null))
            {
                if (customerTemp.Value.getID() == customerID)
                {
                    break;
                }
                else
                {
                    customerTemp = customerTemp.Next;
                }
            }
            if (customerTemp.Equals(null))
            {
                Console.WriteLine("Customer with that ID not found");
                return(false);
            }
            if (customerTemp.Value.getOnContractFlag() == false)
            {
                Console.WriteLine("Customer with that ID is not on a contract");
                return(false);
            }
            while (!contractTemp.Equals(null))
            {
                if (contractTemp.Value.getID() == contractID)
                {
                    break;
                }
                else
                {
                    contractTemp = contractTemp.Next;
                }
            }
            if (contractTemp.Equals(null))
            {
                Console.WriteLine("Contract with that ID not found");
                return(false);
            }
            if (contractTemp.Value.GetCustomerID() != customerID)
            {
                Console.WriteLine("Contract's customerID does not match the one we are trying to remove");
                return(false);
            }
            customerTemp.Value.setOnContractFlag(false);
            contractTemp.Value.SetCustomer(null);
            return(true);
        }
Пример #4
0
 public void remove_all_link_animations()
 {
     while (FirstCyclic != null && FirstCyclic.Previous != null)
     {
         if (CurrAnim.Equals(FirstCyclic.Previous))
         {
             CurrAnim = FirstCyclic;
             if (CurrAnim != null)
             {
                 FrameNumber = CurrAnim.Value.get_starting_frame();
             }
         }
         AnimList.Remove(FirstCyclic.Previous);
     }
 }
        public static LinkedList <string> RealWorldExample1(IList <string> pagesToNavigate)
        {
            //Init
            var        highScorePages = new LinkedList <string>();
            string     baseUrl        = "https://football.ua/";
            IWebDriver webDriver      = WebDriverInitialization.Instance.Driver;


            //Act
            //Navigate pages and receive goals
            pagesToNavigate.ToList().ForEach(page =>
            {
                webDriver.Navigate().GoToUrl(baseUrl + page);
                highScorePages.AddLast(baseUrl + page);
            }
                                             );

            Dictionary <string, int> scorePerPage = PagesDbEmulator.GetScorePerPage();
            LinkedListNode <string>  node         = highScorePages.First;

            while (!node.Equals(null))
            {
                int score = scorePerPage[node.Value];
                if (score < 11)
                {
                    highScorePages.Remove(node);
                }
                node = node.Next;
            }
            return(highScorePages);
        }
Пример #6
0
        private void CleanTail(LinkedListNode <Person> currentNode)
        {
            LinkedListNode <Person> node = PersonList.Last;

            while (!node.Equals(currentNode))
            {
                node = node.Previous;
                PersonList.RemoveLast();
            }
        }
Пример #7
0
        // Recursively check each row in the position from the bottom up until an available one is found, and return that
        private LinkedListNode <Token[]> AddWrapper(int position, ref LinkedListNode <Token[]> row, int pColor)
        {
            LinkedListNode <Token[]> next = row.Next;

            if (row.Equals(row.List.First))
            {
                return(AddWrapper(position, ref next, pColor));
            }
            else if (row.Equals(row.List.Last))
            {
                return(null);
            }
            else if (row.Value[position].GetColor() != 0)
            {
                return(AddWrapper(position, ref next, pColor));
            }
            else
            {
                return(row);
            }
        }
Пример #8
0
        public void ChangePerson()
        {
            Person person = EnterPerson();

            Console.Write("Person: ");
            person.Display();
            PersonList.AddAfter(CurrentNode, person);
            CurrentNode = CurrentNode.Next;
            if (!CurrentNode.Equals(PersonList.Last))
            {
                CleanTail(CurrentNode);
            }
        }
Пример #9
0
        /**
         * Returns a list of Directions. The angle of the first direction is always zero, because if there is no
         * previous point or node passed in, the robot assumes that it is starting off facing the
         * correct direction.
         *
         * @param scale The coordinates/unit of measurement as determined by the map.
         * @return A LinkedList of Direction objects specifying the correct order of direction.
         */
        public LinkedList <Direction> getListOfDirections(double scale)
        {
            LinkedList <Direction> listOfDirections = new LinkedList <Direction>();
            Node previousNode = null;

            LinkedListNode <Node> currentLinkedListNode = listOfNodes.First;

            while (!currentLinkedListNode.Equals(listOfNodes.Last))
            {
                LinkedListNode <Node> nextLinkedListNode = currentLinkedListNode.Next;
                Node currentNode = currentLinkedListNode.Value;
                Node nextNode    = nextLinkedListNode.Value;
                listOfDirections.AddLast(new Direction(previousNode, currentNode, nextNode, scale));
                previousNode          = currentNode;
                currentLinkedListNode = nextLinkedListNode;
            }
            return(listOfDirections);
        }
Пример #10
0
            /// <summary>
            /// Создание нового объекта возможно только после того как созданы узлы вершин
            /// </summary>
            /// <param name="tg"></param>
            /// <param name="edgeNum"></param>
            public EdgeGraphNode(TriangleGraph tg, short edgeNum, Point2d pt)
            {
                if (edgeNum > 2 || edgeNum < 0)
                {
                    throw new ArgumentException(nameof(edgeNum));
                }

                if (!tg.vertexNodes.All(n => n != null))
                {
                    throw new ArgumentException(nameof(tg));
                }

                TriangleGraph = tg;
                EdgeNum       = edgeNum;

                //Расчитать параметр для этого узла
                Parameter = (pt - tg.vert2dLocs[edgeNum]).Length / tg.edgesLength[edgeNum];

                //Добавить узел в нужное место в графе, заполнить свойство LinkedListNode
                LinkedListNode <GraphNode> lln = tg.vertexNodes[edgeNum];

                do
                {
                    lln = lln.Next != null ? lln.Next : lln.List.First;

                    EdgeGraphNode edgeNode = lln.Value as EdgeGraphNode;
                    if (edgeNode != null && edgeNode.Parameter > Parameter)
                    {
                        //Если обнаружен узел с большим параметром, то выход из цикла
                        break;
                    }
                } while (!(lln.Value is VertexGraphNode));

                if (!lln.Equals(tg.vertexNodes[0]))
                {
                    LinkedListNode = tg.graphNodes.AddBefore(lln, this);
                }
                else//????На первом месте в списке всегда должна быть первая вершина. Перед ней ничего не вставляется. Вместо этого в конец списка
                {
                    LinkedListNode = tg.graphNodes.AddLast(this);
                }
            }
Пример #11
0
        // time complexity: O(n^2)
        // space complexity: O(1)
        public static LinkedList <int> RemoveDups2(LinkedList <int> lnkUnsorted)
        {
            LinkedListNode <int> node = lnkUnsorted.First;

            while (node != null)
            {
                LinkedListNode <int> node2 = lnkUnsorted.First;
                while (node2 != null)
                {
                    if (node2.Value == node.Value && !node2.Equals(node))
                    {
                        lnkUnsorted.Remove(node2);
                    }

                    node2 = node2.Next;
                }
                node = node.Next;
            }
            return(lnkUnsorted);
        }
Пример #12
0
        public static LinkedListNode <int> GetIntersectionNode(LinkedList <int> linkedList1, LinkedList <int> linkedList2)
        {
            if (linkedList1 == null || linkedList2 == null)
            {
                return(null);
            }
            LinkedList <int> shortLinkedList;
            LinkedList <int> longLinkedList;

            if (linkedList1.Count > linkedList2.Count)
            {
                shortLinkedList = linkedList2;
                longLinkedList  = linkedList1;
            }
            else
            {
                shortLinkedList = linkedList1;
                longLinkedList  = linkedList2;
            }

            LinkedListNode <int> shortLinkedListHead = shortLinkedList.First;
            LinkedListNode <int> longLinkedListHead  = longLinkedList.First;

            for (int i = 0; i < longLinkedList.Count - shortLinkedList.Count; i++)
            {
                longLinkedListHead = longLinkedListHead.Next;
            }

            while (shortLinkedListHead.Next != null)
            {
                if (shortLinkedListHead.Equals(longLinkedListHead))
                {
                    return(shortLinkedListHead);
                }
                shortLinkedListHead = shortLinkedListHead.Next;
                longLinkedListHead  = longLinkedListHead.Next;
            }

            return(null);
        }
Пример #13
0
        private void DoDelete(LinkedListNode <FileSystemModelEntry> node)
        {
            if (node == null)
            {
                return;
            }

            if (_lastVisibleNode != null && _lastVisibleNode.Equals(node))
            {
                _lastVisibleNode = _lastVisibleNode.Previous;
            }

            if (node.Value.Visible)
            {
                node.Value.Visible = false;
                _visibleEntriesCount--;

                Debug.Assert(_visibleEntriesCount >= 0);
            }

            _entries.Remove(node);
        }
Пример #14
0
 public void invokeCommand(Command c)
 {
     if (commands.Count == 0 || currentCommand.Equals(dummyFirst))
     {
         commands.Clear();
         commands.AddLast(c);
         currentCommand = commands.First;
     }
     else
     {
         while (!currentCommand.Equals(commands.Last))
         {
             commands.RemoveLast();
         }
         commands.AddAfter(currentCommand, c);
         currentCommand = currentCommand.Next;
     }
     currentCommand.Value.execute();
 }
Пример #15
0
 public bool is_first_cyclic()
 {
     return(CurrAnim == null || CurrAnim.Equals(FirstCyclic));
 }
Пример #16
0
    public static int MaxProfitWithKTransactions(int[] prices, int k)
    {
        LinkedList <int[]> trends = new LinkedList <int[]>();
        int tempstart             = 0;
        int tempend = 0;

        trends.AddFirst(new int[] { 0, 0, 0, 0 });
        LinkedListNode <int[]> current = trends.Last;

        for (int i = 1; i < prices.Length; i++)
        {
            current = trends.Last;
            if (prices[i] > prices[i - 1])
            {
                tempend       = i;
                current.Value = new int[] { tempstart, tempend, prices[tempstart], prices[tempend] };
            }
            else
            {
                if (i != prices.Length - 1)
                {
                    trends.AddLast(new int[] { tempstart, tempend, prices[tempstart], prices[tempend] });
                }
                tempstart = i;
                tempend   = i;
            }
        }

        //TRENDS is the initial trends case, there are no limits for how many increases there are.
        //Now we implement a way of merging or removing the transactions with minimal loss.

        int profit = 0;

        if (k >= trends.Count)         //no minimizing necessary
        //calculate profit full
        {
            foreach (int[] data in trends)
            {
                profit += (data[3] - data[2]);                 //profit adds finish - initial
            }
        }

        LinkedList <int[]> merging = trends;

        for (int i = trends.Count; i > k; i -= 1)                  //removal / merge
        {
            LinkedListNode <int[]> lowestcausenode = trends.First; //Just a node.
            int lowestcause = 10000;
            LinkedListNode <int[]> currentnode = trends.First;
            bool finalremoval = false;
            bool first        = true;
            for (int index = 0; index < trends.Count; index++)
            {
                int   cause     = 0;
                bool  isremoval = false;
                int[] data      = currentnode.Value;
                if (currentnode.Equals(trends.First) || currentnode.Equals(trends.Last))
                {
                    if (currentnode.Equals(trends.First))                                                      //..
                    {
                        lowestcause = data[3] - data[2];                                                       //this is just to set the lowestcause as a base!!!
                    }                                                                                          //..
                    cause     = data[3] - data[2];
                    isremoval = true;
                }
                else                   //MERGE the current into the next and find the cause (PROFIT 1 + PROFIT 2) - (2LAST - 1START)
                {
                    int[] next       = currentnode.Next.Value;
                    int   tprofit    = (data[3] - data[2]) + (next[3] - next[2]);
                    int   tnewprofit = (next[3] - data[2]);
                    cause = tprofit - tnewprofit;
                }
                if (currentnode.Equals(trends.First))
                {
                    int[] next       = currentnode.Next.Value;
                    int   tprofit    = (data[3] - data[2]) + (next[3] - next[2]);
                    int   tnewprofit = (next[3] - data[2]);
                    if (tprofit - tnewprofit < cause)
                    {
                        cause = tprofit - tnewprofit;
                    }
                }
                if (first)
                {
                    first           = false;
                    lowestcause     = cause;
                    lowestcausenode = currentnode;
                    finalremoval    = isremoval;
                }
                if (cause < lowestcause)
                {
                    lowestcause     = cause;
                    lowestcausenode = currentnode;
                    finalremoval    = isremoval;
                }
                currentnode = currentnode.Next;
                if (currentnode == null)
                {
                    break;
                }
            }
            if (finalremoval)
            {
                merging.Remove(currentnode);
            }
            else
            {
                int[] currentdata = lowestcausenode.Value;
                int[] nextdata    = lowestcausenode.Next.Value;
                merging.Remove(lowestcausenode.Next);
                lowestcausenode.Value = new int[] { currentdata[0], nextdata[1], currentdata[2], nextdata[3] };
            }

            //merging / removal complete

            foreach (int[] data in merging)
            {
                profit += (data[3] - data[2]);                 //profit adds finish - initial
            }
        }

        return(profit);
    }
Пример #17
0
        /// <summary>
        /// Calculates the shortest path between the airplane and the point through which it has to leave the airspace.
        /// </summary>
        /// <param name="points">All the checkpoints in the airspace. No airstrips, no airplanes.</param>
        /// <param name="exitCheckpoint">The checkpoint through which the plane has to leave the airspace.</param>
        public void CalculateShortestPathLeavingAirspace(List <Checkpoint> points)
        {
            this.ReachableNodes.Clear();
            this.ShortestPath.Clear();

            foreach (Checkpoint point in points)
            {
                if (target == null && point.ParentCellType == CellType.FINAL)
                {
                    this.AddSingleDestination(point, CalculateTimeBetweenPoints(point));
                }
                else if (target != null && target.Equals(ShortestPath.Last)
                         ) //if this doesn't work: ((Checkpoint)target.Value).ParentCellType == Cell.BORDER
                {
                    ShortestPath.Clear();
                    ShortestPath.AddFirst(target);
                    return;
                }
                else if (target != null && point.ParentCellType == ((Checkpoint)target.Value).ParentCellType)
                {
                    this.AddSingleDestination(point, CalculateTimeBetweenPoints(point));
                }

                point.ShortestPath.Clear();
                point.DistanceFromSource = int.MaxValue;
            }

            exitDestination.DistanceFromSource = int.MaxValue;
            exitDestination.ShortestPath.Clear();

            HashSet <AbstractCheckpoint> settledCheckpoints   = new HashSet <AbstractCheckpoint>();
            HashSet <AbstractCheckpoint> unsettledCheckpoints = new HashSet <AbstractCheckpoint> {
                this
            };


            while (unsettledCheckpoints.Count != 0)
            {
                AbstractCheckpoint currentCheckpnt = this.GetLowestDistanceNode(unsettledCheckpoints);
                unsettledCheckpoints.Remove(currentCheckpnt);
                foreach (var pair in currentCheckpnt.ReachableNodes)
                {
                    AbstractCheckpoint reachableCheckpoint = pair.Key;
                    double             edgeWeight          = pair.Value;

                    if (!settledCheckpoints.Contains(reachableCheckpoint))
                    {
                        var shortestPath = CalculateMinDistance(reachableCheckpoint, edgeWeight, currentCheckpnt);
                        if (shortestPath != null && reachableCheckpoint.GetType() == typeof(Checkpoint) &&
                            ((Checkpoint)reachableCheckpoint).ParentCellType == CellType.BORDER)
                        {
                            shortestPath.AddLast(reachableCheckpoint);

                            this.ShortestPath = new LinkedList <AbstractCheckpoint>();
                            var pathNode = shortestPath.First;

                            while (pathNode != null)
                            {
                                this.ShortestPath.AddLast(pathNode.Value);
                                pathNode = pathNode.Next;
                            }
                        }

                        unsettledCheckpoints.Add(reachableCheckpoint);
                    }
                }

                settledCheckpoints.Add(currentCheckpnt);
            }

            if (this.ShortestPath.Count != 0)
            {
                movingDirectionHasChanged = true;
                target = ShortestPath.First;
                target = target.Next;
            }
        }
Пример #18
0
    private bool Overlap(LinkedListNode<ShiftABGameObject> node, LinkedListNode<ShiftABGameObject> otherNode, int patternSize)
    {
        for (int i = 0; i < patternSize; i++)
        {
            if(node == null)
                break;

            if(node.Equals(otherNode))
               return true;

            node = node.Next;
        }

        return false;
    }