Exemple #1
0
        public List <bool> Go()
        {
            ISinglyCell <int> cell1 = null;
            ISinglyCell <int> next  = null;
            int i = 0;

            while (i < 4)
            {
                if (cell1 == null)
                {
                    cell1       = new SinglyCell <int>();
                    cell1.Value = 1;
                    i++;
                    next = cell1;
                    continue;
                }
                ISinglyCell <int> cell = new SinglyCell <int>();
                cell.Value = 1;
                next.Next  = cell;
                next       = next.Next;
                i++;
            }
            ISinglyCell <int> outer = cell1;

            while (outer.Next != null)
            {
                if (outer.Value == outer.Next.Value)
                {
                    outer.Next = outer.Next.Next;
                }
            }

            return(new List <bool>());
        }
Exemple #2
0
        // O(N)
        private ISinglyCell <int> InsertNodeAtPosition(ISinglyCell <int> head, int position, int value)
        {
            SinglyCell <int> newNode = new SinglyCell <int> {
                Value = value
            };

            if (head == null)
            {
                head = newNode;
            }
            if (position == 1)
            {
                newNode.Next = head;
                return(newNode);
            }
            int k = 1;
            ISinglyCell <int> prevNode = head;
            ISinglyCell <int> nextNode = head;

            while (nextNode != null && k < position)
            {
                k++;
                prevNode = nextNode;
                nextNode = nextNode.Next;
            }
            prevNode.Next = newNode;
            newNode.Next  = nextNode;
            return(head);
        }
        public List <string> Sort()
        {
            List <string> resList = new List <string>();

            ISinglyCell <int> cell     = firstOrderedLinkedList.First();
            ISinglyCell <int> sentinel = new SinglyCell <int>();

            sentinel.Next = null;
            while (cell != null)
            {
                // Get the next cell to add to the list.
                ISinglyCell <int> nextCell = cell;
                // Move input to input.Next for the next trip through the loop.
                cell = cell.Next;
                // See where to add the next item in the sorted list.
                ISinglyCell <int> afterMe = sentinel;
                while (afterMe.Next != null && afterMe.Next.Value < nextCell.Value)
                {
                    afterMe = afterMe.Next;
                }

                // Insert the item in the sorted list.
                nextCell.Next = afterMe.Next;
                afterMe.Next  = nextCell;
            }

            return(resList);
        }
        public List <string> Go()
        {
            ISinglyCell <int> cell      = CreatingLinkedList.Create(new SinglyCell <int>(), 10, true);
            ISinglyCell <int> givenNode = new SinglyCell <int>();

            givenNode.Value = 5465;
            ISinglyCell <int> res = InsertIntoSortingLinkedList(cell, givenNode);

            return(new List <string>());
        }
        private ISinglyCell <int> CreateLinkedListFromBST(IBinaryNode <int> root, ISinglyCell <int> linkedNode)
        {
            var currentNode = linkedNode;

            if (root.LeftNode != null)
            {
                currentNode = CreateLinkedListFromBST(root.LeftNode, currentNode);
            }

            var node = new SinglyCell <int>();

            node.Value       = root.Value;
            currentNode.Next = node;
            currentNode      = node;

            if (root.RightNode != null)
            {
                CreateLinkedListFromBST(root.RightNode, currentNode);
            }

            return(currentNode);
        }