隊列的基本操作-創(chuàng)新互聯(lián)

structComm.h //定義各種結(jié)構(gòu)的頭文件

創(chuàng)新互聯(lián)服務(wù)項目包括鄂城網(wǎng)站建設(shè)、鄂城網(wǎng)站制作、鄂城網(wǎng)頁制作以及鄂城網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,鄂城網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到鄂城省份的部分城市,未來相信會繼續(xù)擴大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
#ifndef STRUCTCOMM_H_INCLUDED
#define STRUCTCOMM_H_INCLUDED

#undef NULL
#ifdef __cplusplus
    #define NULL 0
#else
    #define NULL ((void *)0)
#endif

struct list_head
{
    struct list_head *next;
    struct list_head *prev;
};

typedef struct tag_myTree
{
    int data;
    struct tag_myTree* pLeft;
    struct tag_myTree* pRight;
}myTree;

typedef struct tag_myStack
{
    int data;
    myTree *pTree;
    struct list_head stStack;
}myStack;

typedef struct tag_myQue
{
    int data;
    myTree *pTree;
    struct list_head stQue;
}myQue;

#endif // STRUCTCOMM_H_INCLUDED

myQue.h

#ifndef MYQUE_H_INCLUDED
#define MYQUE_H_INCLUDED

#include "structComm.h"

myQue* getNewNode();
void initQue(myQue *pRoot);
void destoryQue(myQue *pRoot);
int getQueLen(myQue *pRoot);
int isQueEmpty(myQue *pRoot);
void enQue(myQue *pRoot, myQue *pNew);
myQue* deQue(myQue *pRoot);

#endif // MYQUE_H_INCLUDED

myQue.c

#include "myQue.h"
#include "myList.h"

myQue* getNewQueNode()
{
    myQue *pTmp = NULL;

    pTmp = (myQue *)malloc(sizeof(myQue));
    if (NULL == pTmp)
    {
        return NULL;
    }

    pTmp->data = 0;
    pTmp->pTree = NULL;
    INIT_LIST_HEAD(&(pTmp->stQue));

    return pTmp;
}

void initQue(myQue *pRoot)
{
    pRoot->data = 0;
    pRoot->pTree = NULL;
    INIT_LIST_HEAD(&(pRoot->stQue));

    return;
}

void destoryQue(myQue *pRoot)
{
    struct list_head *pos = NULL;
    struct list_head *n = NULL;
    myQue *pstQue = NULL;

    list_for_each_safe(pos, n, &(pRoot->stQue))
    {
        list_del(pos);
        pstQue = list_entry(pos, myQue, stQue);
        free(pstQue);
        pos = n;
    }

    return;
}

int getQueLen(myQue *pRoot)
{
    int len = 0;
    struct list_head *pos = NULL;

    list_for_each(pos, &(pRoot->stQue))
    {
        len++;
    }

    return len;
}

int isQueEmpty(myQue *pRoot)
{
    return list_empty(&(pRoot->stQue));
}

void enQue(myQue *pRoot, myQue *pNew)
{
    list_add(&(pNew->stQue), &(pRoot->stQue));
}

myQue* deQue(myQue *pRoot)
{
    myQue *pstQue = NULL;
    struct list_head *pTmp = NULL;

    if (!isQueEmpty(pRoot))
    {
        pTmp = (pRoot->stQue).prev;
        list_del((pRoot->stQue).prev);
        pstQue = list_entry(pTmp, myQue, stQue);
        return pstQue;
    }

    return NULL;
}

main.c

#include <stdio.h>
#include "myQue.h"

myQue g_stQueRoot;      //棧的頭節(jié)點,不存儲數(shù)據(jù)

int main()
{
    int i = 0;
    myQue *pNewNode = NULL;

    initQue(&g_stQueRoot);  //初始化之前要保證頭隊列為空
    printf("is empty:\t%d\n", isQueEmpty(&g_stQueRoot));

    for (i = 0; i < 5; i++)
    {
        pNewNode = getNewNode();
        if (NULL == pNewNode)
        {
            exit(0);
        }

        pNewNode->data = i;
        enQue(&g_stQueRoot, pNewNode);
    }

    printf("is empty:\t%d\n", isQueEmpty(&g_stQueRoot));
    printf("que len:\t%d\n", getQueLen(&g_stQueRoot));

    printf("de:\t");
    for (i = 0; i < 5; i++)
    {
        pNewNode = deQue(&g_stQueRoot);
        printf("%d\t", pNewNode->data);
    }

    pNewNode = deQue(&g_stQueRoot);
    if (NULL == pNewNode)
    {
        printf("\ncan not de\n");
    }

    return 0;
}

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

網(wǎng)頁名稱:隊列的基本操作-創(chuàng)新互聯(lián)
網(wǎng)頁路徑:http://www.bm7419.com/article28/ceedjp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號、全網(wǎng)營銷推廣、搜索引擎優(yōu)化、企業(yè)網(wǎng)站制作定制開發(fā)、定制網(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)

網(wǎng)站優(yōu)化排名