如何使用两个堆栈实现队列
Queue:
队列:
A queue is a data structure for storing data where the order in which data arrives is important. The queue is implemented as FIFO (First in First Out).
队列是用于存储数据的数据结构,数据到达的顺序很重要。 该队列被实现为FIFO(先进先出)。
The queue is an ordered list in which insertions are done at one end (rear) and deletions are done from another end (front). The first element that got inserted is the first one to be deleted (basic principle of FIFO).
队列是一个有序列表,其中插入是在一端(后部)完成,而删除是从另一端(前部)完成。 插入的第一个元素是要删除的第一个元素(FIFO的基本原理)。
The main Queue operations are:
队列的主要操作是:
EnQueue (int data): Insertion at rear end
EnQueue(int数据):在后端插入
int DeQueue(): Deletion from front end
int DeQueue():从前端删除
Stack:
堆栈:
A stack is also another data structure which is implemented as LIFO.
堆栈也是另一个实现为LIFO的数据结构。
The stack is an ordered list where insertion and deletion are done from the same end, top. The last element that entered first is the first one to be deleted (the basic principle behind the LIFO).
堆栈是一个有序列表,其中插入和删除从同一末端开始。 首先输入的最后一个元素是要删除的第一个元素(LIFO的基本原理)。
The main stack operations are:
主要的堆栈操作是: