Ejemplo n.º 1
0
        public string Display(Node_LinkedList head)
        {
            string          result = String.Empty;
            Node_LinkedList start  = head;
            StringBuilder   sb     = new StringBuilder();

            while (start != null)
            {
                sb.AppendFormat("{0} ", start.Data);
                start = start.Next;
            }

            result = sb.ToString();

            return(result);
        }
Ejemplo n.º 2
0
        protected string PrintLinkedList(Node_LinkedList head)
        {
            string result;

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("{0} ", head.Data);
            while (head.Next != null)
            {
                head = head.Next;
                sb.AppendFormat("{0} ", head.Data);
            }

            result = sb.ToString();

            return(result);
        }
        public Node_LinkedList RemoveDuplicateNodes(Node_LinkedList head)
        {
            var current  = head;
            int nodeData = current.Data;

            while (current.Next != null)
            {
                if (nodeData == current.Next.Data)

                {
                    var duplicate = current.Next;
                    current.Next = duplicate.Next;
                    duplicate    = null;
                }
                else
                {
                    current  = current.Next;
                    nodeData = current.Data;
                }
            }
            return(head);
        }
Ejemplo n.º 4
0
        public Node_LinkedList Insert(Node_LinkedList head, int data)
        {
            Node_LinkedList nextNode = new Node_LinkedList(data);

            //Complete this method
            if (head != null)
            {
                Node_LinkedList tail = head;

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

                tail.Next = nextNode;
            }

            else
            {
                head = nextNode;
            }

            return(head);
        }