Exemple #1
0
        public bool Remove(T element)
        {
            if (this.root == null)
            {
                return(false);
            }

            var currentRoot = this.root;

            if (currentRoot.Element.CompareTo(element) == 0)
            {
                this.root = currentRoot.NextElement;
                return(true);
            }

            while (currentRoot.NextElement != null)
            {
                var next = currentRoot.NextElement;

                if (next.Element.CompareTo(element) == 0)
                {
                    currentRoot.NextElement = next.NextElement;
                    return(true);
                }

                currentRoot = currentRoot.NextElement;
            }

            return(false);
        }
Exemple #2
0
        public void Add(T element)
        {
            if (this.root == null)
            {
                this.root = new MyGenericLinkedListNode <T>(element);
                return;
            }

            var currentRoot = this.root;

            while (currentRoot.NextElement != null)
            {
                currentRoot = currentRoot.NextElement;
            }

            currentRoot.NextElement = new MyGenericLinkedListNode <T>(element);
        }
Exemple #3
0
 public MyGenericLinkedList(T root)
 {
     this.root = new MyGenericLinkedListNode <T>(root);
 }