看完复仇看了看队列。花了半小时来编写、调试。写完博客再去温习下枪火
/*
** File name: SeqQueue.h
** Author: ZhouFeng
** Date: 2012/03/27
*/
#ifndef SEQ_QUEUE_H
#define SEQ_QUEUE_H
#define BOOL int
#define ERROR 0
#define SUCCESS 1
#define TRUE 1
#define FALSE 0
#define MAX_SIZE 100
typedef int EleType;
typedef struct SeqQueue
{
EleType _seqQueue[MAX_SIZE];
/* End of queue */
int nRear;
/* Front of queue */
int nFront;
/* Counter number of element */
int nCount;
}SeqQueue;
/* Operation */
void InitSeqQueue(SeqQueue *Q);
int SeqQueueAppend(SeqQueue *Q, EleType data);
int SeqQueueDelete(SeqQueue *Q, EleType *data);
BOOL IsQueueEmpty(SeqQueue *Q);
int GetQueue(SeqQueue *Q, EleType *data);
#endif
/*
** File name: SeqQueue.c
** Author: ZhouFeng
** Date: 2012/03/27
*/
#include <stdlib.h>
#include <stddef.h>
#include "SeqQueue.h"
void InitSeqQueue(SeqQueue *Q)
{
/* Deal Q is NULL pointer. */
if(Q == NULL)
{
return;
}
Q->nRear = 0;
Q->nFront = 0;
Q->nCount = 0;
}
int SeqQueueAppend(SeqQueue *Q, EleType data)
{
if(Q == NULL)
{
return ERROR;
}
/* Deal Q is full. */
if(Q->nCount > 0 && Q->nFront == Q->nRear)
{
return ERROR;
}
/* Insert at the end of Queue */
Q->_seqQueue[Q->nRear] = data;
++(Q->nRear);
Q->nRear %= MAX_SIZE;
++(Q->nCount);
return SUCCESS;
}
int SeqQueueDelete(SeqQueue *Q, EleType *data)
{
if(Q == NULL)
{
return ERROR;
}
/* Deal with Q is empty. */
if(Q->nCount == 0)
{
return ERROR;
}
*data = Q->_seqQueue[Q->nFront];
Q->nFront += 1;
Q->nFront %= MAX_SIZE;
--(Q->nCount);
return SUCCESS;
}
BOOL IsQueueEmpty(SeqQueue *Q)
{
if(Q == NULL)
{
return FALSE;
}
if(Q->nCount == 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
int GetQueue(SeqQueue *Q, EleType *data)
{
if(Q == NULL)
{
return ERROR;
}
if(Q->nCount == 0)
{
return FALSE;
}
*data = Q->_seqQueue[Q->nFront];
return SUCCESS;
}
/* End ~SeqQueue.c*/
分享到:
相关推荐
循环队列.cpp
标志量循环队列出队int deletequeue(seqqueue Q,queueelementtype x).cpp
标志量循环队列初始化void initqueue(seqqueue Q).cpp
1. Queue.hpp是队列的基类,只定义基本操作,具体实现在另外两个hpp文件中 2. seqQueue.hpp是循环队列的实现 3. linkQueue.hpp是链式队列的实现 4. test.cpp是简单的测试文件,main函数在这里面
void Initseqqueue(seqqueue &q) //循环队列初始化 { q.front =q.rear=0; printf("初始化成功!\n"); } int enqueue(seqqueue &q,int e) //数据元素e入队列 { if((q.rear+1)%MAXSIZE==q.front) { printf("循环...
5、顺序栈 SeqStack.h Test.cpp 6、链式栈 StackNode.h LinkStack.h Test.cpp 7、顺序队列 SeqQueue.h Test.cpp 8、链式队列 QueueNode.h LinkQueue.h Test.cpp
class SeqQueue //循环队列的类定义 { public: SeqQueue(){ maxSize=50; element=new T[maxSize]; front=0; rear=0; } ~SeqQueue(){delete[] element;} //析构函数 bool EnQueue(const T& x); //若队列不满,则将x...
循环队列: 1.循环队列中判断队空的方法是判断front==rear,队满的方法是判断front=(rear+1)%maxSize。(我曾经想过为什么不用一个length表示队长,当length==maxSize时队满)原因就是,在频繁的队列操作中,多出...
补充并改正
typedef struct { QElemType* base; int front; int rear; }SeqQueue;
和上篇栈的实现基本是一个思路: 废话不多说,直接写代码吧 //自定义队列接口 namespace 队列 { interface IQueue ...//顺序队列的实现类 namespace 队列 { class SeqQueue<T> : IQueue { private
seqqueue1.h
#include <stdio.h> #include <stdlib.h> #define MAX 100 ...//顺序队列的初始化 SeqQueue SeqQueueInit() { SeqQueue Q; //队头和队尾相等即为空队列 Q.front = Q.rear = 0; return Q; }
SeqQueue.zip
7.顺序队列 37 SeqQueue.h 37 Test.cpp 40 8、链式队列 41 QueueNode.h 41 LinkQueue.h 42 Test.cpp 44 9、优先级队列 45 QueueNode.h 46 Compare.h 46 PriorityQueue.h 47 Test.cpp 51 10、串 52 MyString.h 52 ...
7.顺序队列 69 SeqQueue.h 69 Test.cpp 75 8、链式队列 77 QueueNode.h 77 LinkQueue.h 78 Test.cpp 83 9、优先级队列 85 QueueNode.h 85 Compare.h 86 PriorityQueue.h 88 Test.cpp 94 10、串 97 MyString.h 97 ...
7、顺序队列 62 SeqQueue.h 63 Test.cpp 68 8、链式队列 70 QueueNode.h 70 LinkQueue.h 71 Test.cpp 75 9、优先级队列 77 QueueNode.h 77 Compare.h 78 PriorityQueue.h 80 Test.cpp 85 10、串 88 MyString.h 88 ...
7、顺序队列 62 SeqQueue.h 63 Test.cpp 68 8、链式队列 70 QueueNode.h 70 LinkQueue.h 71 Test.cpp 75 9、优先级队列 77 QueueNode.h 77 Compare.h 78 PriorityQueue.h 80 Test.cpp 85 10、串 88 MyString.h 88 ...
7、顺序队列 62 SeqQueue.h 63 Test.cpp 68 8、链式队列 70 QueueNode.h 70 LinkQueue.h 71 Test.cpp 75 9、优先级队列 77 QueueNode.h 77 Compare.h 78 PriorityQueue.h 80 Test.cpp 85 10、串 88 MyString.h 88 ...