Ejemplo n.º 1
0
        public void TestMethodStackPop()
        {
            CStack <string> s = new CStack <string>();

            Assert.AreEqual(s.Size, 0);
            s.Push("a");
            s.Push("b");
            s.Push("c");
            Assert.AreEqual(s.Top(), "c");
            s.Pop();
            Assert.AreEqual(s.Top(), "b");
            s.Pop();
            Assert.AreEqual(s.Top(), "a");

            s.Pop();
            Assert.IsTrue(s.IsEmpty());
            Assert.ThrowsException <Exception>(() => s.Top());
            Assert.ThrowsException <Exception>(() => s.Pop());
        }
Ejemplo n.º 2
0
        public static void RunStack()
        {
            CStack <int> s = new CStack <int>();

            for (int i = 1; i <= 3; i++)
            {
                s.Push(i);
            }
            Console.WriteLine(s);
            s.Pop();
            Console.WriteLine(s);
            s.Pop();
            Console.WriteLine(s);
            s.Pop();
            Console.WriteLine(s);

            Console.WriteLine(s.Size);
            Console.WriteLine(s.IsEmpty());

            //Console.ReadLine();
        }
Ejemplo n.º 3
0
        // Start is called before the first frame update
        void Start()
        {
            // 제네틱 사용하지 않았을때 스택을 사용하는 코드

            int          size   = 5;
            CStack <int> istack = new CStack <int>(size);


            for (int i = 0; i < 7; i++)
            {
                if (!istack.IsFull())
                {
                    istack.Push(i);
                }
                else
                {
                    Debug.Log("스택이 꽉 찼습니다. [저장 실패 : " + i + "]");
                }
            }

            while (!istack.IsEmpty())
            {
                Debug.Log(istack.Pop());
            }



            CStack <float> fstack = new CStack <float>(size);

            for (int i = 0; i < 7; i++)
            {
                if (!fstack.IsFull())
                {
                    fstack.Push(i * 1.2f);
                }
                else
                {
                    Debug.Log("스택이 꽉 찼습니다. [저장 실패 : " + i + "]");
                }
            }

            while (!fstack.IsEmpty())
            {
                Debug.Log(fstack.Pop());
            }



            CStack <string> sstack = new CStack <string>(size);

            for (int i = 0; i < 7; i++)
            {
                if (!sstack.IsFull())
                {
                    sstack.Push(i + "번");
                }
                else
                {
                    Debug.Log("스택이 꽉 찼습니다. [저장 실패 : " + i + "]");
                }
            }

            while (!sstack.IsEmpty())
            {
                Debug.Log(sstack.Pop());
            }
        }