Beispiel #1
0
        public Iterator <G> getReverseIterator()
        {
            ReverseIterator it = new ReverseIterator();

            it.setCurrentNode(tail);
            return(it);
        }
Beispiel #2
0
        private static ReverseIterator CheckOutwardCodeEnd(ReverseIterator iterator, ref CharStack stack)
        {
            // This checks for outward parts ending in 1A, 11 or 1
            char endChar = iterator.GetNext();

            if (IsLetter(endChar))
            {
                if (!IsNumber(iterator.GetNext()))
                {
                    return(ReverseIterator.Invalid);
                }

                stack.Push(endChar);
            }
            else if (IsNumber(endChar))
            {
                ReverseIterator lookAhead = iterator;
                if (IsNumber(lookAhead.GetNext()))
                {
                    return(lookAhead);
                }
            }
            else
            {
                return(ReverseIterator.Invalid);
            }

            return(iterator);
        }
Beispiel #3
0
        /// <inheritdoc />
        public override int CheckInwardCode(string postcode, int index)
        {
            var iterator = new ReverseIterator(this.SkipInvalid, postcode, index);

            if (IsValidInwardAlpha(iterator.GetNext()) &&
                IsValidInwardAlpha(iterator.GetNext()) &&
                IsNumber(iterator.GetNext()))
            {
                return(iterator.Index);
            }

            return(InvalidPostcode);
        }
Beispiel #4
0
        /// <summary>
        /// Gets the index of the start of the outward code.
        /// </summary>
        /// <param name="postcode">The value to check.</param>
        /// <param name="index">
        /// The index to the start of the inward part or of the whitespace
        /// between the parts.
        /// </param>
        /// <returns>
        /// The start of the outward part of the postcode, or -1 the part is invalid.
        /// </returns>
        public virtual int CheckOutwardCode(string postcode, int index)
        {
            // Three basic scenarios:
            // + Letter Number Letter (Letter) - AA1A/A1A
            // + Number Number Letter (Letter) - AA11/A11
            // + Number Letter (Letter) - AA1/A1
            var iterator = new ReverseIterator(this.SkipInvalid, postcode, index);

            iterator = CheckOutwardCodeEnd(iterator);
            if (IsLetter(iterator.GetNext()))
            {
                ReverseIterator lookAhead = iterator;
                return(IsLetter(lookAhead.GetNext()) ? lookAhead.Index : iterator.Index);
            }

            return(InvalidPostcode);
        }
Beispiel #5
0
        /// <inheritdoc />
        public override int CheckOutwardCode(string postcode, int index)
        {
            // Three basic scenarios:
            // + Letter Number Letter (Letter) - AA1A/A1A
            // + Number Number Letter (Letter) - AA11/A11
            // + Number Letter (Letter) - AA1/A1
            var iterator = new ReverseIterator(this.SkipInvalid, postcode, index);
            var stack    = new CharStack(3);

            iterator = CheckOutwardCodeEnd(iterator, ref stack);

            char current = iterator.GetNext();

            if (IsLetter(current))
            {
                stack.Push(current);

                int             start;
                ReverseIterator lookAhead = iterator;
                current = lookAhead.GetNext();
                if (IsLetter(current))
                {
                    stack.Push(current);
                    start = lookAhead.Index;
                }
                else
                {
                    start = iterator.Index;
                }

                if (AreValidOutwardLetters(stack))
                {
                    return(start);
                }
            }

            return(InvalidPostcode);
        }
Beispiel #6
0
        public IEnumerable <T> GetReverse()
        {
            ReverseIterator container = new ReverseIterator(this);

            return(container);
        }
 public ReverseIterator(ReverseIterator iterator)
 {
     currentNode = iterator.currentNode;
 }
Beispiel #8
0
        static void Main(string[] args)
        {
            LinkedList lista1 = new LinkedList();

            lista1.add(1);
            lista1.add(4);
            lista1.add(3);
            lista1.add(7);


            Console.WriteLine("El tamaño es " + lista1.getSize());

            //int data = lista1.get(2);
            //Console.WriteLine("El dato en 2 es:  " + data);

            for (int i = 0; i < lista1.getSize(); i++)
            {
                Console.WriteLine("El dato en " + i + "es: " + lista1.get(i));
            }

            //Console.WriteLine("-----------------------------");

            Iterator        it  = lista1.getIterator();
            ReverseIterator it2 = lista1.getReverseIterator();

            while (it.hasNext())
            {
                Iterator backupIt = new Iterator(it);
                int      element  = it.next(); //regresar el dato y avanzar el iterador

                if (element == 3)
                {
                    lista1.insert(10, LinkedList.BEFORE, backupIt);
                }

                if (element == 7)
                {
                    lista1.insert(15, LinkedList.AFTER, backupIt);
                }
            }

            Console.WriteLine("-----------------------------");
            Console.WriteLine("El tamaño es " + lista1.getSize());
            for (int i = 0; i < lista1.getSize(); i++)
            {
                Console.WriteLine("El dato en " + i + "es: " + lista1.get(i));
            }

            lista1.delete(1);
            Console.WriteLine("-----------------------------");
            Console.WriteLine("El tamaño es " + lista1.getSize());

            for (int i = 0; i < lista1.getSize(); i++)
            {
                Console.WriteLine("El dato en " + i + "es: " + lista1.get(i));
            }

            Console.WriteLine("-----------------------------");

            it = lista1.getIterator();
            while (it.hasNext())
            {
                int element = it.next();

                Console.WriteLine("dato: " + element);
            }

            Console.WriteLine("-----------------------------");

            it2 = lista1.getReverseIterator();

            while (it2.hasNext())
            {
                int element = it2.previous();

                Console.WriteLine("Dato: " + element);
            }
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            LinkedList.LinkedList lista1 = new LinkedList.LinkedList();

            lista1.add(1);
            lista1.add(4);
            lista1.add(3);
            lista1.add(7);

            Iterator it = lista1.getIterator();

            System.Console.WriteLine("-----Imprimimos Lista Original-----");

            while (it.hasNext())
            {
                int element = it.next();

                System.Console.WriteLine("Dato: " + element);
            }

            System.Console.WriteLine("-----Insertamos según posición-----");

            it = lista1.getIterator();

            while (it.hasNext())
            {
                Iterator backupIt = new Iterator(it);
                int      element  = it.next();

                if (element == 3)
                {
                    lista1.insert(10, LinkedList.LinkedList.BEFORE, backupIt);
                }

                if (element == 7)
                {
                    lista1.insert(15, LinkedList.LinkedList.AFTER, backupIt);
                }
            }

            it = lista1.getIterator();

            while (it.hasNext())
            {
                int element = it.next();

                System.Console.WriteLine("Dato: " + element);
            }

            System.Console.WriteLine("-----Eliminamos el valor 3-----");

            lista1.delete(3);

            System.Console.WriteLine("--- El tamaño es:" + lista1.getSize() + " ---");

            it = lista1.getIterator();

            while (it.hasNext())
            {
                int element = it.next();

                System.Console.WriteLine("Dato: " + element);
            }

            System.Console.WriteLine("-----Recorremos la lista con el ReverseIterator-----");

            ReverseIterator reverseIterator = lista1.getReverseIterator();

            while (reverseIterator.hasNext())
            {
                int element = reverseIterator.next();

                System.Console.WriteLine("Dato: " + element);
            }

            Console.ReadKey();
            Console.ReadKey();
        }