Ejemplo n.º 1
0
        // Method to Ray a List object.
        public static void Ray(List list)
        {
            // Create the auxiliary object. 
            Element aux = list.fist;
            
            // Write the "List Size" text.
            Console.WriteLine("List size: ");
            Console.Write("{");

            // If the list is void the console will setup a message "Null"
            if(aux == null)
            {
                Console.Write("Null");
            }

            // If the list have something rhe console will ray the list.
            else
            {
                while (aux != null)
                {
                    Console.Write("[" + aux.i + "]");
                    aux = aux.next;
                }
            }

            Console.WriteLine("}");
        }
Ejemplo n.º 2
0
        // Method to get the lenght of a list.
        public static int Count(List list)
        {

            // Fist element.
            Element aux = list.fist;

            // When the aux object
            while (aux != null)
            {
                aux = aux.next;
                list.count++;
            }

            // Return the list.count
            return list.count;
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            // Fist instace from the list of elements
            List list = new List();

            list.Initialize(15);

            list.Ray();

            Console.WriteLine("List Length: " + list.Count());

            list.Remove(5);

            Console.WriteLine("List Length: " + list.Count());
            
            Console.WriteLine("List Element: " + list.FindByIndex(5).i);

            // The text to say what the user whant to increment in the list.    
            Console.ReadLine();
        }
Ejemplo n.º 4
0
        // Method to find a element in a list by one element.
        public static void FindByIndex(List list, int index)
        {
            // Element to do the search.
            Element aux = list.fist;

            // This while will scroll to find the element or reach your final.
            while(aux != null && aux.i != index)
            {
                aux = aux.next;
            }
            // If not find write the menssage not find. 
            if(aux == null)
            {
                Console.Write("Element not find...");
            }
            // If find, write the element index.
            else
            {
                Console.Write("{[" + aux.i + "]}");
            }
        }
Ejemplo n.º 5
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 ++;
            }
        }