题目描述:http://ac.jobdu.com/problem.php?pid=1512
用两个栈来实现一个队列,完成队列的Push和Pop操作。
队列中的元素为int类型。解析:
定义2个栈s1, s2
1. 开始时,将元素push进s1
2. front()或pop()时,将s1的数据,出栈,顺序压入s2; 此时发现 s2 的出栈顺序即队列的出队列顺序。
3. 再次push时,仍然...
分类:
其他好文 时间:
2015-07-25 23:04:59
阅读次数:
144
队列是操作受限的线性表,只允许在队尾插入元素,在队头删除元素,为了便于插入元素,设立队尾指针。这样,插入元素的操作与队列长度无关
队列的链式存储结构typedef struct QNode
{
QElemType data;
QNode *next;
}*QueuePtr;
struct LinkQueue
{
QueuePtr front, rear;//队头,队尾指针...
分类:
其他好文 时间:
2015-07-25 15:18:37
阅读次数:
123
1 #include 2 #include 3 using namespace std; 4 #define size 10 5 struct squeue 6 { 7 int queue[size]; 8 int front,rear; 9 };10 void initqu...
分类:
其他好文 时间:
2015-07-23 17:37:17
阅读次数:
120
1 #include 2 using namespace std; 3 struct squeue 4 { 5 int data; 6 squeue *next; 7 }; 8 struct link 9 {10 squeue* front;11 squeue ...
分类:
其他好文 时间:
2015-07-23 17:28:15
阅读次数:
160
原文地址:http://blog.csdn.net/leather0906/article/details/6593003运行android程序的时候提示:ActivityManager: Warning: Activity not started, its current task has bee...
分类:
其他好文 时间:
2015-07-23 17:18:13
阅读次数:
169
Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empty() --...
分类:
其他好文 时间:
2015-07-21 17:22:00
阅读次数:
109
队列(Queue)的定义:只允许在一端进行插入另一端进行删除操作的线性表。允许插入的一端称为队尾(rear) ,允许删除的一端称为队头(front)。 具有“先进先出”特点。队列也是线性表,所以也存在顺序结构和链式结构。顺序队列:对于队列,入队操作的解释为:
(是在队尾追加一个元素,不需要移动任何元素,因此时间复杂度为0(1)。)
判断队列是否已满;
如果没满则先给队尾元素赋值;
然后将队尾指针后...
分类:
编程语言 时间:
2015-07-21 10:42:46
阅读次数:
114
Implement the following operations of a queue using stacks.
push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empty(...
分类:
其他好文 时间:
2015-07-18 11:03:29
阅读次数:
99
#ifndef PALINDROME_H_#define PALINDROME_H_#include#includeint palindrome_longest(char *str,int front,int back); #endif #include"Palindrome.h"#define M...
分类:
其他好文 时间:
2015-07-17 20:52:05
阅读次数:
238
队列是一种特殊的线性表
队列仅在线性表的两端进行操作
队头(Front):取出数据元素的一端
队尾(Rear):插入数据元素的一端
队列不允许在中间部位进行操作!
queue常用操作
销毁队列
清空队列
进队列
出队列
获取队头元素
获取队列的长度
队列也是一种特殊的线性表;可以用线性表顺序存储来模拟队列。
主要代码:
// seqqueue.h
// 顺...