---
title: "用两个栈实现一个队列的功能？"
author: "standalone"
date: "2010-01-04T10:37:43Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2010-01-04T10:37:43Z"
id: 561892
url: "https://standalone.iteye.com/blog/561892"
---

用两个栈，栈A作为入队，栈B作为出队。

 

enqueue(){

   将入队数据压到A的栈顶；

}

dequeue(){

   if B 为空；

        if A 不为空；

              弹出A数据到B中，然后弹出B的一个数据作为出队数据；

        else

           队列空；

   else

        弹出B的一个数据作为出队数据；

}