public void TestCorrecString()
        {
            myStack tst      = new myStack("5 5 +");
            double  expected = 10;

            Assert.AreEqual(expected, tst.myPop(), "test passed");
        }
Example #2
0
        public void Checkcountnpush()
        {
            myStack s1 = new myStack(10);

            s1.push(1);
            s1.push(2);
            s1.push(3);
            Assert.AreEqual(3, s1.Count());
        }
Example #3
0
        public void Checkpeek()
        {
            myStack s3 = new myStack(10);

            s3.push(1);
            s3.push(2);
            s3.push(3);
            Assert.AreEqual(3, s3.peek());
        }
Example #4
0
        public new void Reverse()
        {
            myStack <T> reverseStack = new myStack <T>();

            while (this.Peek != null)
            {
                myStack.Push(this.Pop);
            }
        }
Example #5
0
        public void checkPeek()
        {
            myStack s3 = new myStack(10);

            s3.push(1);
            s3.push(2);
            s3.push(3);
            s3.push(4);
            Assert.AreEqual(4, s3.peek());
        }
Example #6
0
        public void CheckPop()
        {
            myStack s2 = new myStack(10);

            s2.push(1);
            s2.push(2);
            s2.push(3);
            Assert.AreEqual(3, s2.pop());
            Assert.AreEqual(2, s2.peek());
        }
Example #7
0
        public void CreatedMyStack()
        {
            myStack s1 = new myStack(10);

            s1.push(1);
            s1.push(2);
            s1.push(3);
            s1.push(4);
            Assert.AreEqual(4, s1.checkcount());
        }
Example #8
0
        public void checkPop()
        {
            myStack s2 = new myStack(10);

            s2.push(1);
            s2.push(2);
            s2.push(3);
            s2.push(4);
            Assert.AreEqual(4, s2.pop());
        }
Example #9
0
 public T Pop()
 {
     if (!Empty())
     {
         LengthStack--;
         T d = prev.data;
         prev = prev.prev;
         return(d);
     }
     return(default(T));
 }
Example #10
0
        public int LargestRectangleArea(int[] heights)
        {
            int     max = 0;
            myStack ms  = new myStack();

            for (int i = 0; i < heights.Length; i++)
            {
                int start = heights[i];
                max = Math.Max(ms.Push(start, i), max);
            }
            max = Math.Max(ms.Push(int.MinValue, heights.Length), max);
            return(max);
        }
Example #11
0
    public Class1()
    {
        myStack <int> s = new myStack <int>();

        s.Push(1);
        s.Push(2);
        s.Push(3);
        s.Push(4);
        s.Pop();
        s.Reverse();
        s.Display();
        reverseStack <int>(s);
    }
Example #12
0
        public int MaximalRectangle(char[,] matrix)
        {
            int length0 = matrix.GetLength(0);
            int length1 = matrix.GetLength(1);

            int[,] DP = new int[length0, length1];
            #region initDP
            for (int i = 0; i < length0; i++)
            {
                for (int j = 0; j < length1; j++)
                {
                    if (DP[i, j] != 0 || matrix[i, j] == '0')
                    {
                        continue;
                    }
                    int k = i; int num = 0;
                    while (k < length0 && matrix[k, j] != '0')
                    {
                        num++;
                        k++;
                    }
                    k = i;
                    while (num > 0)
                    {
                        DP[k, j] = num;
                        num--;
                        k++;
                    }
                }
            }
            #endregion
            int max = 0;
            for (int i = 0; i < length0; i++)
            {
                myStack ms = new myStack();
                for (int j = 0; j < length1; j++)
                {
                    int start = DP[i, j];
                    max = Math.Max(ms.Push(start, j), max);
                }
                max = Math.Max(ms.Push(int.MinValue, length1), max);
            }
            return(max);
        }
Example #13
0
        static void Main(string[] args)
        {
            myStack user = new myStack(10); // space of data in stack;

            user.push(1);
            user.push(2);
            user.push(3);
            user.push(4);

            /*Console.WriteLine(@"-----Peek lasted element and the element still stay in stack");
             * user.peek();
             * user.checkcount(); */
            Console.WriteLine(@"-----Pop lasted element and that element go out the stack");
            user.pop();
            user.checkcount();
            /* the count will count down when every time pop */
            Console.WriteLine(@"----Pop againt");
            user.pop();
            user.checkcount();
        }
Example #14
0
        static void Main(string[] args)
        {
            //TemplateList<int> t = new TemplateList<int>();
            //t.Add(1);
            //t.Add(2);
            //t.Display(t);

            //TemplateList<int> tChar = new TemplateList<int>();
            //tChar.Add('A');
            //tChar.Add('B');
            //t.Display(tChar);
            //Console.ReadKey();

            //TemplateList<int> intStack = new TemplateList<int>();

            //intStack.Push(2);
            //intStack.Push(3);
            //intStack.Pop();
            //intStack.Display(intStack);

            //StackLL<int> myStack = new StackLL<int>();
            //myStack.Push(1);
            //myStack.Push(2);
            //while (myStack.noOfElements) ;
            //{

            //}
            myStack <int> s = new myStack <int>();

            s.Push(1);
            s.Push(2);
            s.Push(3);
            s.Push(4);
            s.Pop();
            s.Reverse();
            s.Display();
            reverseStack <int>(s);
        }
 // Use this for initialization
 void Start()
 {
     stackInt = new myStack <int>();
 }
Example #16
0
        /* THE MAIN OPERATION STARTS HERE */
        static void Main(string[] args)
        {
            myStack st = new myStack();

            /* to loop the menu */
            while (true)
            {
                Console.Clear(); //'clear' in array class method list
                Console.WriteLine("\nStack MENU(size -- 100)");
                Console.WriteLine("1. Add Notebook");
                Console.WriteLine("2. Check Notebook");
                Console.WriteLine("3. Peek at Notebook");
                Console.WriteLine("4. Check All");
                Console.WriteLine("5. Exit");
                Console.Write("Select your choice: ");

                String choice = Console.ReadLine();

                switch (choice)

                {
                case "1":
                    Console.WriteLine("Enter the name of notebook : ");
                    st.daPush(Console.ReadLine());
                    break;


                case "2":
                    if (st.isEmpty() || st.isNull())
                    {
                        Console.WriteLine("Please add a notebook.");
                    }

                    else
                    {
                        Console.WriteLine(st.daPop() + "'s notebook is being checked.");
                    }

                    break;

                // below is same as case 2

                //case 3:

                //Console.WriteLine("Element removed: {0}", st.daPop());

                // break;

                case "3":
                    Console.WriteLine("Top element is: {0}", st.daPeek());
                    break;

                case "4":
                    st.daDisplay();
                    st.daClean();
                    break;

                case "5":
                    Environment.Exit(0);
                    break;
                }

                Console.ReadKey();
            }
        }
 [ExpectedException(typeof(myException))] // ожидает что теструемый модуль вернет исключение при таком входе
 public void TestIncorrectString()
 {
     myStack tst = new myStack("5 +");
 }
Example #18
0
 private myStack(T newData, myStack <T> linkStak)
 {
     data = newData;
     prev = linkStak;
 }
Example #19
0
 public void Push(T param)
 {
     LengthStack++;
     prev = new myStack <T>(param, prev);//todo здесь ты создаешь новый объект в памяти, так что такая реализация точно не может быть корректной применительно к "ссылка на предыдущий элемент"
 }