Exemple #1
0
        // Method to increment one value in the element list.
        public void Add(int value)
        {
            // Create the newElement Element(), this object represent the element that will be added in the Element() list.fist and the Element() list.last 
            Element newElement = new Element();
            Element eleAux = new Element();

            // If the list size is equals to 0, the last and the fist will be the same object refere.
            if (index.Equals(0))
            {
                newElement.i = value;

                newElement.next = null;

                // The fist element is equals to the last element
                fist = newElement;
                last = newElement;

                // Increment the list size..
                index++;
            }

            // If the list have more of one element.
            else
            {
                // element instance for different objects, now that the list has more than one element they must be different.
                eleAux = fist;

                // Filling in the list...
                while (eleAux.next != null)
                {
                    eleAux = eleAux.next;
                }

                newElement.i = value;

                // The last element don't set no value for a instace (in the future, the last object can set a reference to the fist object).
                newElement.next = null;

                eleAux.next = newElement;
                last = newElement;
                index++;
            }
        }
Exemple #2
0
        public void Remove(int value)
        {
            Element elementToRemove = new Element();
            Element eleAux = new Element();

            // element instance for different objects, now that the list has more than one element they must be different.
            eleAux = fist;

            // Filling in the list...
            while (eleAux.next.i != value)
            {
                eleAux = eleAux.next;
            }

            Console.WriteLine(eleAux.i);

        }
Exemple #3
0
        // Method to increment one value in the element list.
        public static void Add(List list, int value = 0)
        {
            // Create the newElement Element(), this object represent the element that will be added in the Element() list.fist and the Element() list.last 
            Element newElement = new Element();
            Element eleAux     = new Element();

            // If the list size is equals to 0, the last and the fist will be the same object refere.
            if (list.index.Equals(0))
            {
                // Turn the in strig value a value setted in the method call or a string written by the user.
                if (value == null)
                {
                    // Setting to the user write the a element to add.
                    Console.WriteLine("Set the next proprity: ");
                    newElement.i = Console.Read();
                } 
                else
                {
                    Console.WriteLine("Defaut Value stting... ");
                    newElement.i = value;
                }

                newElement.next = null;

                // The fist element is equals to the last element
                list.fist = newElement;
                list.last = newElement;

                // Increment the list size..
                list.index ++;
            }
            
            // If the list have more of one element.
            else
            {
                // element instance for different objects, now that the list has more than one element they must be different.
                eleAux = list.fist;

                // Filling in the list...
                while(eleAux.next != null )
                {
                    eleAux = eleAux.next;
                }

                // Turn the in strig value a value setted in the method call or a string written by the user.
                if (value == null)
                {
                    Console.WriteLine("Set the next proprity: ");
                    newElement.i = Console.Read();
                }
                else
                {
                    newElement.i = value;
                    Console.WriteLine("Defaut Value stting... ");
                }

                // The last element don't set no value for a instace (in the future, the last object can set a reference to the fist object).
                newElement.next = null;

                eleAux.next = newElement;
                list.last = newElement;
                list.index ++;
            }
        }