第7周实践项目1.1 环形队列中用队尾和队的元素个数来实现队列的算法库
生活随笔
收集整理的這篇文章主要介紹了
第7周实践项目1.1 环形队列中用队尾和队的元素个数来实现队列的算法库
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
typedef struct
{Elemtype date[maxsize];int front;int count;
}sqqueue;
void initqueue (sqqueue *&q)
{q=(sqqueue*)malloc((sizeof(sqqueue)));q->front=0;q->count=0;
}
bool enqueue(sqqueue *&q,Elemtype e)
{int rear;if(q->count==maxsize)//隊列上溢return false;rear=(q->front+q->count)%maxsize;//求隊尾位置rear=(rear+1)%maxsize;//隊尾位置加一q->date[rear]=e;q->count++;return true;
}
bool dequeue(sqquque *&q,Elemtype &e)
{if(q->count==0)return false;q->front=(q->front+1)%maxsize;e=q->date[q->front];q->count--;return true;
}
bool queueempty(sqqueue *q)
{return q->count==0;//判斷空隊列
}
總結
以上是生活随笔為你收集整理的第7周实践项目1.1 环形队列中用队尾和队的元素个数来实现队列的算法库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 第7周项目实践 1 队列算法库的建立
- 下一篇: 第7周实践项目2 队列的链式存储结构及