#include stdlib.h // malloc, free
創(chuàng)新互聯(lián)建站是專業(yè)的烏蘭網(wǎng)站建設(shè)公司,烏蘭接單;提供成都網(wǎng)站制作、成都網(wǎng)站建設(shè),網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行烏蘭網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!
#include "queue.h"
struct queue * queue_create(void)
{
struct queue *q = (struct queue *)malloc(sizeof(struct queue));
if (q == NULL) { // malloc failed
return NULL;
}
q-head = dnode_create();
q-tail = dnode_create();
q-head-next = q-tail;
q-tail-prev = q-head;
q-size = 0;
return q;
}
void queue_destroy(struct queue *q)
{
if (q != NULL) {
while (!queue_isempty(q)) {
queue_dequeue(q);
}
dnode_destroy(q-head);
dnode_destroy(q-tail);
free(q);
q = NULL;
}
}
int queue_front(const struct queue * const q)
{
return q-tail-prev-data;
}
void queue_enqueue(struct queue * const q, const int e)
{
struct dnode *dn = dnode_create();
dn-data = e;
struct dnode *tmp = q-head-next;
q-head-next = dn;
dn-prev = q-head;
dn-next = tmp;
tmp-prev = dn;
q-size += 1;
}
int queue_dequeue(struct queue * const q)
{
struct dnode *dn = q-tail-prev;
struct dnode *tmp = dn-prev;
tmp-next = q-tail;
q-tail-prev = tmp;
int ret = dn-data;
dnode_destroy(dn);
q-size -= 1;
return ret;
}
int queue_size(const struct queue * const q)
{
return q-size;
}
int queue_isempty(const struct queue * const q)
{
return q-size 0 ? 0 : 1;
}
//////////////////////
static void bubble_sort(int * const a, const int n)
{
int swapped = 1;
while (swapped) {
swapped = 0;
for (int i = 1; i n; i++) {
if (a[i] a[i - 1]) {
int tmp = a[i];
a[i] = a[i - 1];
a[i - 1] = tmp;
swapped = 1;
}
}
}
}
bool?dequeue(sqqueue?*q,char?e)
{
if(queueempty(q))
return?false;
q-front++;
e=q-date[q-front];
return?true;
}
一個很簡單的小問題,dequeue的參數(shù)e 應(yīng)該是引用哦
q.push(m); // queue是C++STL模板庫的東西,需要使用push來插入元素,詳細信息你可以參考MSDN來了解其使用及內(nèi)容。
當(dāng)前標(biāo)題:c語言調(diào)用queue函數(shù) c語言調(diào)用函數(shù)時
本文鏈接:http://bm7419.com/article10/dohjogo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機網(wǎng)站建設(shè)、電子商務(wù)、網(wǎng)站導(dǎo)航、品牌網(wǎng)站建設(shè)、Google、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)