首页 > 学院 > 开发设计 > 正文

C# 栈的使用 STACK

2019-11-11 01:35:11
字体:
来源:转载
供稿:网友
Stack st = new Stack();            st.Push(1);            st.Push("afd");            st.Push(3.33);            foreach (object o in st)//不是出队操作,是循环遍历            {                Console.WriteLine(o);//输出的顺序和我插入的顺序是相反的            }            //for (int j = 0; j < st.Count; j++)            //{            //    Console.WriteLine(st[j]);//不支持这种方式,编译时报错            //}            st.Pop();//栈顶元素3.33出栈            st.Push(4);//4从栈顶入栈            while (st.Count > 0)//元素依次出栈并且输出            {                object o = st.Pop();                Console.WriteLine(o);            }
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表