热线电话:13121318867

登录
首页精彩阅读经典算法研究系列;BFS和DFS优先搜索算法(3)
经典算法研究系列;BFS和DFS优先搜索算法(3)
2015-01-24
收藏

经典算法研究系列;BFS和DFS优先搜索算法(3)


上述程序的几点说明:

所以,这里应使用的数据结构的构成方式应该采用下面这种形式:
1)队列的实现中,每个队列结点均为图中的结点指针类型.
定义一个以队列尾部下标加队列长度的环形队列如下:

struct SingleRearSeqQueue;
typedef PVexType   QElemType;
typedef struct SingleRearSeqQueue* PSingleRearSeqQueue;
struct SingleRearSeqQueue
{
 int rear;
 int quelen;
 QElemType dataPool[MAXNUM];
};
其余基本操作不再赘述.    


2)堆栈的实现中,每个堆栈中的结点元素均为一个指向队列的指针,定义如下:
#define SEQ_STACK_LEN 1000
#define StackElemType PSingleRearSeqQueue
struct SeqStack;
typedef struct SeqStack* PSeqStack;
struct SeqStack
{
 StackElemType dataArea[SEQ_STACK_LEN];
 int slot;
};
为了提供更好的封装性,对这个堆栈实现两种特殊的操作

2.1) deQueueInSt操作用于将栈顶结点的队列中的队首元素弹出.
void deQueueInSt(PSeqStack inStack)
{
 if(isEmptyQueue(seqTop(inStack))||isNullSeqStack(inStack))
 {
  printf("in deQueueInSt,under flow!/n");
  return;    
 }    
 deQueue(seqTop(inStack));
 if(isEmptyQueue(seqTop(inStack)))
  inStack->slot--;
}

2.2) frontQueueInSt操作用以返回栈顶结点的队列中的队首元素.
QElemType frontQueueInSt(PSeqStack inStack)
{
 if(isEmptyQueue(seqTop(inStack))||isNullSeqStack(inStack))
 {
  printf("in frontQueueInSt,under flow!/n");
  return      '/r'; 
 }    
 
 return getHeadData(seqTop(inStack));
}

 

===================

数据分析咨询请扫描二维码

若不方便扫码,搜微信号:CDAshujufenxi

最新资讯
更多
客服在线
立即咨询