Exemple #1
0
        public void AddCellToStartTest()
        {
            // arrange
            LinkedList <int> list = new LinkedList <int>();
            var lastCell          = new LinkedListCell <int>(1);

            // act
            list.AddCellToStart(lastCell);

            // assert
            Assert.Equal(1, list.Count());
        }
Exemple #2
0
        public LinkedListCell <T> GetByIndex(int i)
        {
            int currentNumber = 0;
            LinkedListCell <T> currentCell = TopCell;

            while (currentNumber < i)
            {
                currentCell = currentCell.Next;
                currentNumber++;
            }

            return(currentCell);
        }
Exemple #3
0
        public void AddCellToStart(LinkedListCell <T> cell)
        {
            // если список пустой, то просто заполняем первую ячейку
            if (TopCell == null)
            {
                TopCell = cell;
                return;
            }

            // кладём в новую ячейку предыдущую головную ячейку списка
            cell.Next = TopCell;

            // заменяем голову списка на новую
            TopCell = cell;
        }
Exemple #4
0
        public void AddSecondCellToEndTest()
        {
            // arrange
            LinkedList <int> list = new LinkedList <int>();
            var firstCell         = new LinkedListCell <int>(1);

            list.AddCellToEnd(firstCell);
            var lastCell = new LinkedListCell <int>(1);

            // act
            list.AddCellToEnd(lastCell);

            // assert
            Assert.Same(firstCell, list.TopCell);
            Assert.Same(lastCell, list.TopCell.Next);
        }
Exemple #5
0
        public void FindIndexWithSpecifiedInformation()
        {
            // arrange
            LinkedList <int> list = new LinkedList <int>();
            var firstCell         = new LinkedListCell <int>(7);
            var secondCell        = new LinkedListCell <int>(10);
            var thirdCell         = new LinkedListCell <int>(4);

            list.AddCellToEnd(firstCell);
            list.AddCellToEnd(secondCell);
            list.AddCellToEnd(thirdCell);

            // act
            var found = list.GetByIndex(1);

            // assert
            Assert.Same(secondCell, found);
        }
Exemple #6
0
        public void AddThreeCellsToEndTest()
        {
            // arrange
            LinkedList <int> list = new LinkedList <int>();
            var firstCell         = new LinkedListCell <int>(1);
            var secondCell        = new LinkedListCell <int>(1);
            var thirdCell         = new LinkedListCell <int>(1);

            // act
            list.AddCellToEnd(firstCell);
            list.AddCellToEnd(secondCell);
            list.AddCellToEnd(thirdCell);

            // assert
            Assert.Same(firstCell, list.TopCell);
            Assert.Same(secondCell, list.TopCell.Next);
            Assert.Same(thirdCell, list.TopCell.Next.Next);
        }
Exemple #7
0
        public void AddCellToEnd(LinkedListCell <T> lastCell)
        {
            // проверяем, что у нас вообще есть головная ячейка и если нет, то заполняем её
            if (TopCell == null)
            {
                TopCell = lastCell;
                return;
            }

            // бежим по ячейкам до самого конца списка. тут чем больше у нас элементов, тем дольше и сложнее бежать
            var currentCell = TopCell;

            while (currentCell.Next != null)
            {
                currentCell = currentCell.Next;
            }

            currentCell.Next = lastCell;
        }