zoukankan      html  css  js  c++  java
  • 使用两个栈实现队列

    前言

    原理后续补齐,语言c#

    代码

    class Program
    {
    	
    	public class generateQueue
    	{
    		public Stack<int> stackin = new Stack<int>();
    
    		public Stack<int> stackout = new Stack<int>();
    		public void push (int element){
    			stackin.Push(element);
    		}
    
    		public int outQuery()
    		{
    			if (stackout.Count == 0)
    			{
    				while (stackin.Count != 0)
    				{
    					stackout.Push(stackin.Pop());
    				}
    			}
    		   return stackout.Pop();
    		}
    
    		public int count {
    			get { return stackin.Count + stackout.Count; }
    		}
    	}
      
    	static void Main(string[] args)
    	{
    		generateQueue generateQueueInstance = new generateQueue();
    		generateQueueInstance.push(10);
    		if (generateQueueInstance.count != 0)
    		{
    			generateQueueInstance.outQuery();
    		}
    		Console.ReadKey();
    	}
    }
    
  • 相关阅读:
    python之基础2
    python之文件2
    python之入门2
    python之入门
    python之多并发2
    python之面向对象2
    python之MySQL系列
    python之文件
    python之多并发
    Google身份验证器详解
  • 原文地址:https://www.cnblogs.com/aoximin/p/12526118.html
Copyright © 2011-2022 走看看