没有合适的资源?快使用搜索试试~ 我知道了~
只是个比较好的代码 我用了感觉不错 所以推荐了
资源推荐
资源详情
资源评论
#include< iostream.h >
#include"stdlib.h"
typedef int QElemType;
#define ok 1
#define overflow 0
#define error 0
typedef struct Qnode {
QElemType data;
struct Qnode *next;
}Qnode,*Queueptr;
typedef struct {
Queueptr front;
Queueptr rear;
}LinkQueue;
InitQueue( LinkQueue &Q ) {
Q.front = Q.rear = ( Queueptr )malloc( sizeof( Qnode ));
if( !Q.front ) exit ( overflow );
Q.front->next =NULL;
return ok;
}
EnQueue( LinkQueue &Q,QElemType e ) {
Queueptr p;
p = ( Queueptr )malloc( sizeof( Qnode ));
if( !p ) exit( overflow );
p->data = e;p->next = NULL;
Q.rear->next = p;
#include"stdlib.h"
typedef int QElemType;
#define ok 1
#define overflow 0
#define error 0
typedef struct Qnode {
QElemType data;
struct Qnode *next;
}Qnode,*Queueptr;
typedef struct {
Queueptr front;
Queueptr rear;
}LinkQueue;
InitQueue( LinkQueue &Q ) {
Q.front = Q.rear = ( Queueptr )malloc( sizeof( Qnode ));
if( !Q.front ) exit ( overflow );
Q.front->next =NULL;
return ok;
}
EnQueue( LinkQueue &Q,QElemType e ) {
Queueptr p;
p = ( Queueptr )malloc( sizeof( Qnode ));
if( !p ) exit( overflow );
p->data = e;p->next = NULL;
Q.rear->next = p;
Q.rear = p;
return ok;
}
DeQueue( LinkQueue &Q,QElemType &e ) {
Queueptr p;
if( Q.front == Q.rear ) return error;
p = Q.front->next;
e = p->data;
Q.front->next = p->next;
if( Q.rear == p ) Q.rear = Q.front;
free( p );
return ok;
}
void VisitQueue( LinkQueue Q ) {
Queueptr p;
p = Q.front->next;
while( p ) { cout << p->data << " ";p = p->next; }
}
CompareQueue( LinkQueue Q,int page ) {
Queueptr p;
p = Q.front->next;
while( p ) {
if( p->data == page ) return ok;
p = p->next;
}
return error;
}
return ok;
}
DeQueue( LinkQueue &Q,QElemType &e ) {
Queueptr p;
if( Q.front == Q.rear ) return error;
p = Q.front->next;
e = p->data;
Q.front->next = p->next;
if( Q.rear == p ) Q.rear = Q.front;
free( p );
return ok;
}
void VisitQueue( LinkQueue Q ) {
Queueptr p;
p = Q.front->next;
while( p ) { cout << p->data << " ";p = p->next; }
}
CompareQueue( LinkQueue Q,int page ) {
Queueptr p;
p = Q.front->next;
while( p ) {
if( p->data == page ) return ok;
p = p->next;
}
return error;
}
剩余6页未读,继续阅读
资源评论
shallyou
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功