Exemple #1
0
        public override string Print()
        {
            string temp        = null;
            int    i           = 0;
            int    count_print = count;


            if (count_print == 0)
            {
                temp += "[\n"; // beginning of the stack which is the same as 1st element in the array
            }
            SortCars test_obj = arrayA[0] as SortCars;

            if (test_obj != null)
            {
                while (count_print > 0)
                {
                    if (i == 0)
                    {
                        test_obj = arrayA[i] as SortCars;
                        temp    += "[\n" + test_obj.Print() + "\n";
                        i++;
                    }
                    else
                    {
                        test_obj = arrayA[i] as SortCars;
                        temp    += test_obj.Print() + "\n";
                        i++;
                    }
                    count_print--; // reduce the size of the printed elements
                }
            }
            else
            {
                while (count_print > 0)
                {
                    if (i == 0)
                    {
                        temp += "[ " + arrayA[i]; // print start of the stack
                        i++;
                    }
                    else
                    {
                        temp += ", " + arrayA[i]; // print middle of the stack
                        i++;
                    }
                    count_print--; // reduce the size of the printed elements
                }
            }
            temp += "]\n"; // print the last element of the stack
            return(temp);
        }
Exemple #2
0
        public override string Print()
        {
            string temp = null;

            if (arrayA != null)
            {
                //SortCars [] test_obj = new SortCars[sizeA];
                SortCars test_obj = arrayA[0] as SortCars;
                if (test_obj != null)
                {
                    temp = "\n[\n";
                    for (int i = 0; i < sizeA; i++)
                    {
                        test_obj = arrayA[i] as SortCars;
                        temp    += test_obj.Print() + "\n";
                    }
                    temp += "]\n";
                }
                else
                {
                    temp = "\n[";
                    foreach (var item in arrayA)
                    {
                        temp += item.ToString() + " ";
                    }
                    temp += "]\n";
                }
            }
            return(temp);
        }
Exemple #3
0
        public override string Peek()
        {
            string temp = null;

            if (arrayA != null)
            {
                SortCars test_obj = arrayA[0] as SortCars;
                if (test_obj != null)
                {
                    temp     = "\n[\n ";
                    test_obj = TValue as SortCars;
                    temp     = test_obj.Print() + "\n";
                    return(temp);
                }
            }
            return(TValue.ToString());
        }
Exemple #4
0
        public override string Print()
        {
            string temp        = null;
            int    i           = tail;
            int    count_print = count;

            if (count_print == 0) // if buffer is empty print [ ]
            {
                temp = "[ ]\n";
            }
            SortCars test_obj = arrayA[0] as SortCars;

            while (count_print > 0 && arrayA != null)
            {
                if (test_obj != null)
                {
                    if (i < sizeA) // if printed element is less than the maximum of the array
                    {
                        if (tail == i)
                        {
                            test_obj = arrayA[i] as SortCars;
                            temp    += "[\n " + test_obj.Print() + "\n";
                            i++;
                        }
                        else if (tail != i)
                        {
                            test_obj = arrayA[i] as SortCars;
                            temp    += test_obj.Print() + "\n";
                            i++;
                        }
                    }
                    else if (i >= sizeA) // if index exceed the size of the array
                    {
                        i = 0;
                        if (tail == sizeA) // print start position of the buffer
                        {
                            test_obj = arrayA[i] as SortCars;
                            temp    += "[\n" + test_obj.Print() + "\n";
                            i++;
                        }
                        else // print the middle elements of the buffer
                        {
                            test_obj = arrayA[i] as SortCars;
                            temp    += test_obj.Print() + "\n";
                            i++;
                        }
                    }
                }
                else
                {
                    if (tail == i)
                    {
                        temp += "[ " + arrayA[i]; // print the first element sof the buffer
                        i++;
                    }
                    else if (tail != i)
                    {
                        temp += ", " + arrayA[i]; // middle element
                        i++;
                    }
                    else if (i >= sizeA) // if index exceed the size of the array
                    {
                        i = 0;
                        if (tail == sizeA) // print start position of the buffer
                        {
                            temp += "[ " + arrayA[i];
                            i++;
                        }
                        else // print the middle elements of the buffer
                        {
                            temp += ", " + arrayA[i];
                            i++;
                        }
                    }
                }
                count_print--;
                if (count_print == 0)
                {
                    temp += "]\n";
                }
            }
            return(temp);
        }