钢柱钢梁结构形式:象这样的列表,代码有什么问题吗?

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/30 09:51:31
//-----单链队列-----链式储存结构-----
typedef struct QNode{
QElemType data;
struct QNode *next;
}QNode,*QueuePtr;
typedef struct{
QueuePtr front; //队头指针
QueuePtr rear; //队尾指针
}LinkQueue;
status InitQueue(LinkQueue &Q){
//构造一个空队列Q
Q.front =Q.rear =new QNode;
if (!Q.front )exit(OVERFLOW);
Q.front ->next =NULL;
return OK;
}//InitQueue
status DestroyQueue(LinkQueue &Q){
//销毁队列Q
while (Q.front ){
Q.rear =Q.front ->next ;
free(Q.front );
Q.front =Q.rear ;
}//while
return OK;
}//DestroyQueue
bool QueueEmpty(LinkQueue Q){
//若队列Q为空队列,则返回TRUE;否则返回FALSE;
return (Q.front ==Q.rear );
}//QueueEmpty
int QueueLength(LinkQueue Q){
//返回Q的元素个数,既为队列的长度
QueuePtr p=Q.front ;
int QLength=0;
while(p->next ) {++QLEngth;p=p->next ;}
return QLength;
}//QueueLength
status GetHead(LinkQueue Q,QElemType &e){
//若队列不空,则用e返回Q的队头元素;并返回OK,否则返回ERROR
if QueueEmpty(Q) return ERROR;
e=Q.front ->next ->data ;
return OK;
}//GetHead
status EnQueue(LinkQueue &Q,QElemType e){
//插入元素e为新的队尾元素
QueuePtr p;
p=new QNode;
if (!p) exit(OVERFLOW);
p->data =e;p->next =NULL;
Q.rear ->next =p;
Q.rear =p;
}//EnQueue
status DeQueue(LinkQueue &Q,QElemType &e){
//若队列不空,则删除Q的队头元素,用e返回其值,并返回ok;
//否则返回ERROR
QueuePtr p;
if(Q.front ==Q.rear )return ERROR;
p=Q.front ->next ;
e=p->next ;
Q.front ->next=p->next;
if(Q.rear==p) Q.rear=Q.front;
free(q);
return OK;
}//DeQueue
void PrintQueue(LinkQueue Q){
//若队列不空,则按顺序输出队列
if (!QueueEmpty(Q)) {
QueuePtr p;
p=Q.front ->next ;
cout<<endl<<"队列含有以下元素:"<<endl;
while(p!=Q.rear ){
cout<<p->data <<" ";
p=p->next
}//while
cout<<Q.rear ->data ;
}//if
else cout<<"队列为空";
cout<<endl;
}//PrintQueue

没问题!一切OK