Пример #1
0
        static void Main(string[] args)
        {
            // create and fill a 3 x 3 array of String
            ITwoDArray <String> name_array = new TwoDArrayGeneric <String>(2, 3);

            name_array.Set(0, 0, "Sarah");
            name_array.Set(0, 1, null);
            name_array.Set(0, 2, "Yixin");
            name_array.Set(1, 0, "Tom");
            name_array.Set(1, 1, null);
            name_array.Set(1, 2, "Faizal");


            ITwoDIterator <String> iter_major   = name_array.CreateRowMajorIterator();
            ITwoDIterator <String> iter_reverse = name_array.CreateReverseIterator();

            Console.WriteLine("Reverse transverse Iteration:");
            while (!iter_reverse.IsDone())
            {
                Console.Write(iter_reverse.Current() + " ");
                iter_reverse.Next();
            }

            Console.WriteLine("\n");
            Console.WriteLine("Row major iteration: ");
            while (!iter_major.IsDone())
            {
                Console.Write(iter_major.Current() + " ");
                iter_major.Next();
            }

            Console.WriteLine();
            Console.ReadLine();
        }
Пример #2
0
        static void Main(string[] args)
        {
            // create and fill a 2 x 3 array of integers
            ITwoDArray <int> array = new TwoDArrayGeneric <int>(2, 3);

            array.Set(0, 0, 9); array.Set(0, 1, 4); array.Set(0, 2, 1);
            array.Set(1, 0, 2); array.Set(1, 1, 5); array.Set(1, 2, 3);

            // display the array in row major order
            ITwoDIterator <int> iter = array.CreateRowMajorIterator();

            while (!iter.IsDone())
            {
                Console.Write(iter.Current() + " ");
                iter.Next();
            }
            Console.WriteLine();
            Console.ReadLine();


            // display the array in column major order
            ITwoDIterator <int> iter2 = array.CreateColumnMajorIterator();

            while (!iter2.IsDone())
            {
                Console.Write(iter2.Current() + " ");
                iter2.Next();
            }
            Console.WriteLine();
            Console.ReadLine();
        }
Пример #3
0
 // constructor
 public RowReverseIteractorGeneric(TwoDArrayGeneric <T> collectionIn)
 {
     collection = collectionIn;
     i          = 0;
     j          = 0;
     Console.WriteLine("total col = " + collection.Columns());
     Console.WriteLine("total row = " + collection.Rows());
 }
Пример #4
0
        static void Main(string[] args)
        {
            // create and fill a 2 x 3 array of integers
            ITwoDArray <int> array = new TwoDArrayGeneric <int>(2, 3);

            array.Set(0, 0, 9); array.Set(0, 1, 4); array.Set(0, 2, 1);
            array.Set(1, 0, 2); array.Set(1, 1, 5); array.Set(1, 2, 3);

            ITwoDArray <int> array2 = new TwoDArrayGeneric <int>(3, 3);

            array2.Set(0, 0, 1); array2.Set(0, 1, 2); array2.Set(0, 2, 3);
            array2.Set(1, 0, 4); array2.Set(1, 1, 5); array2.Set(1, 2, 6);
            array2.Set(2, 0, 7); array2.Set(2, 1, 8); array2.Set(2, 2, 9);


            ITwoDArray <String> array3 = new TwoDArrayGeneric <String>(2, 3);

            array3.Set(0, 0, "Sarah"); array3.Set(0, 1, null); array3.Set(0, 2, "Yixin");
            array3.Set(1, 0, null); array3.Set(1, 1, null); array3.Set(1, 2, "Faizal");


            // display the array in row major order
            ITwoDIterator <int>    iter  = array.CreateRowMajorIterator();
            ITwoDIterator <int>    iter2 = array2.CreateFirstIterator();
            ITwoDIterator <string> iter3 = array3.CreateSecondIterator();


            Console.WriteLine("Original iterator");
            while (!iter.IsDone())
            {
                Console.Write(iter.Current() + " ");
                iter.Next();
            }

            Console.WriteLine("");

            Console.WriteLine("First iterator");
            while (!iter2.IsDone())
            {
                Console.Write(iter2.Current() + " ");
                iter2.Next();
            }

            Console.WriteLine("");

            Console.WriteLine("Second iterator");
            while (!iter3.IsDone())
            {
                Console.Write(iter3.Current() + " ");
                iter3.Next();
            }



            Console.WriteLine();
            Console.ReadLine();
        }
Пример #5
0
        static void Main(string[] args)
        {
            // create and fill a 3 x 3 array of integers
            ITwoDArray <String> array = new TwoDArrayGeneric <String>(3, 3);

            // array.Set(0, 0, 9);
            // array.Set(0, 1, 4);
            // array.Set(0, 2, 1);
            // array.Set(1, 0, 2);
            // array.Set(1, 1, 5);
            // array.Set(1, 2, 3);

            // [ "Sarah", null, "Yixin"  ]
            // [  null , null, "Faizal"  ]
            // [ "Daniel", null, "Peter" ]

            array.Set(0, 0, "Sarah");
            array.Set(0, 1, null);
            array.Set(0, 2, "Yixin");
            array.Set(1, 0, null);
            array.Set(1, 1, null);
            array.Set(1, 2, "Faizal");
            array.Set(2, 0, "Daniel");
            array.Set(2, 1, "Peter");
            array.Set(2, 2, null);

            // display the array in row major order
            ITwoDIterator <String> rowIter     = array.CreateRowMajorIterator();
            ITwoDIterator <String> reverseIter = array.CreateReverseIterator();

            // print the output to console
            Console.WriteLine("Reverse traverse iteration: ");
            while (!reverseIter.IsDone())
            {
                var currentValue = reverseIter.Current();
                Console.Write(currentValue + " ");
                reverseIter.Next();
            }

            Console.WriteLine("\n===========================\n");
            Console.WriteLine("Row major iteration: ");

            while (!rowIter.IsDone())
            {
                var currentValue = rowIter.Current();
                Console.Write(currentValue + " ");
                rowIter.Next();
            }

            // pause the console.
            Console.WriteLine();
            Console.ReadLine();
        }
Пример #6
0
        static void Main(string[] args)
        {
            // create and fill a 2 x 3 array of integers
            ITwoDArray <int> array = new TwoDArrayGeneric <int>(2, 3);

            array.Set(0, 0, 9); array.Set(0, 1, 4); array.Set(0, 2, 1);
            array.Set(1, 0, 2); array.Set(1, 1, 5); array.Set(1, 2, 3);

            // display the array in row major order
            ITwoDIterator <int> iter = array.CreateRowMajorIterator();

            while (!iter.IsDone())
            {
                Console.Write(iter.Current() + " ");
                iter.Next();
            }

            Console.WriteLine("\n--row reverse ---");

            // OUTPUT = 9 4 1, 3 5 2
            iter = array.CreateRowReverseIterator();
            while (!iter.IsDone())
            {
                Console.Write(iter.Current() + " ");
                iter.Next();
            }

            Console.WriteLine("\n row major");
            ITwoDArray <string> stringArray = new TwoDArrayGeneric <string>(2, 3);

            stringArray.Set(0, 0, "Sarah");
            stringArray.Set(0, 1, null);
            stringArray.Set(0, 2, "Yixin");
            stringArray.Set(1, 0, null);
            stringArray.Set(1, 1, null);
            stringArray.Set(1, 2, "Faizal");

            ITwoDIterator <string> stringIter = stringArray.CreateRowMajorIterator();

            while (!stringIter.IsDone())
            {
                Console.Write(stringIter.Current() + " ");
                stringIter.Next();
            }

            Console.WriteLine();
            Console.ReadLine();
        }
Пример #7
0
        static void Main(string[] args)
        {
            // create and fill a 2 x 3 array of integers
            ITwoDArray <int> array = new TwoDArrayGeneric <int>(2, 3);

            array.Set(0, 0, 9); array.Set(0, 1, 4); array.Set(0, 2, 1);
            array.Set(1, 0, 2); array.Set(1, 1, 5); array.Set(1, 2, 3);

            // display the array row by row
            // reverse the direction at the end of each row
            ITwoDIterator <int> iter = array.CreateRowMajorIterator();

            while (!iter.IsDone())
            {
                Console.Write(iter.Current() + " ");
                iter.NextTurn();
            }
            Console.WriteLine();

            // create and fill a 3 x 2 array of strings with null values
            ITwoDArray <string> newArray = new TwoDArrayGeneric <string>(3, 2);

            newArray.Set(0, 0, "Sarah"); newArray.Set(0, 1, null);
            newArray.Set(1, 0, "Yixin"); newArray.Set(1, 1, null);
            newArray.Set(2, 0, null); newArray.Set(2, 1, "Faizal");

            // display the array in row major order
            // skip any null references in the array
            ITwoDIterator <string> newIter = newArray.CreateRowMajorIterator();

            while (!newIter.IsDone())
            {
                Console.Write(newIter.Current() + " ");
                newIter.Next();
            }
            Console.WriteLine();
            Console.ReadLine();
        }
Пример #8
0
        static void Main(string[] args)
        {
            // create and fill a 2 x 3 array of integers
            ITwoDArray <string> array = new TwoDArrayGeneric <string>(2, 3);

            array.Set(0, 0, "Sarah"); array.Set(0, 1, null); array.Set(0, 2, "Yixin");
            array.Set(1, 0, "Seng yong"); array.Set(1, 1, null); array.Set(1, 2, "Faizal");

            // display the array in row major order
            ITwoDIterator <string> iter = array.CreateRowMajorIterator();

            Console.Write("\n --Iterator-- \n");
            while (!iter.IsDone())
            {
                Console.Write(iter.Current() + " ");
                iter.Next();
            }

            // create and fill an array of name including nulls
            ITwoDArray <string> nameArray = new TwoDArrayGeneric <string>(2, 3);

            nameArray.Set(0, 0, "Sarah"); nameArray.Set(0, 1, null); nameArray.Set(0, 2, "Yixin");
            nameArray.Set(1, 0, "Seng yong"); nameArray.Set(1, 1, null); nameArray.Set(1, 2, "Faizal");

            // display the array in reverse row major order
            ITwoDIterator <string> iterReverse = nameArray.CreateRowReverseIterator();

            Console.Write("\n\n --Reverse Iterator-- \n");
            while (!iterReverse.IsDone())
            {
                Console.Write(iterReverse.Current() + " ");
                iterReverse.Next();
            }

            Console.WriteLine();
            Console.ReadLine();
        }
Пример #9
0
 // constructor
 public TwoDRowMajorIteratorGeneric(TwoDArrayGeneric <T> collectionIn)
 {
     collection = collectionIn;
     i          = 0;
     j          = 0;
 }
        //constructor

        public TwoDReverseIteratorGeneric(TwoDArrayGeneric <T> collectionIn)
        {
            collection = collectionIn;
            i          = 0;
            j          = 0;
        }