16_队列的顺序存储

时间:2022-02-11 17:38:43
//seqQueue.h
#pragma once


#include "mseqList.h"
using SeqQueue = SeqList;
using SeqQueueNode = SeqListNode;


class seqQueue {

    private :



    public:

        mseqList chen;

        seqQueue();

        ~seqQueue();

        SeqQueue* SeqQueue_Create(int capacity);

        void SeqQueue_Destroy(SeqQueue* queue);

        void SeqQueue_Clear(SeqQueue* queue);

        int SeqQueue_Append(SeqQueue* queue, SeqQueueNode* item);

        void* SeqQueue_Retrieve(SeqQueue* queue);

        void* SeqQueue_Header(SeqQueue* queue);

        int SeqQueue_Length(SeqQueue* queue);

        int SeqQueue_Capacity(SeqQueue* queue);

};

//seqQueue.cpp
#include "seqQueue.h"


seqQueue::seqQueue() { }


seqQueue::~seqQueue() { }


SeqQueue* seqQueue::SeqQueue_Create(int capacity) {

    return chen.SeqList_Create( capacity );
}


void seqQueue::SeqQueue_Destroy(SeqQueue* queue) {

    chen.SeqList_Destroy( queue );
}


void seqQueue::SeqQueue_Clear(SeqQueue* queue) {

    chen.SeqList_Clear( queue );
}


int seqQueue::SeqQueue_Append(SeqQueue* queue, SeqQueueNode* item) {

    cout << "len:" << chen.SeqList_Length(queue)<<" -- a[i]:" << *item << endl;
    return chen.SeqList_Insert( queue , item , chen.SeqList_Length(queue) );
}


void* seqQueue::SeqQueue_Retrieve(SeqQueue* queue) {

    return chen.SeqList_Delete(queue,0);
}


void* seqQueue::SeqQueue_Header(SeqQueue* queue) {

    return chen.SeqList_Get(queue,0);
}


int seqQueue::SeqQueue_Length(SeqQueue* queue) {

    return chen.SeqList_Length(queue);
}


int seqQueue::SeqQueue_Capacity(SeqQueue* queue) {

    return chen.SeqList_Capacity(queue);
}

//main.cpp
#include "seqQueue.h"

int main( int argc , char *argv[] ) {

    seqQueue chen;
    SeqQueue *queue = chen.SeqQueue_Create(20);
    unsigned int a[10] = { 0 };
    for (int i = 0; i < 10; ++i ) {
        a[i] = i  ;
        chen.SeqQueue_Append(queue , a+i);
    }

    for (int i = 0; i < 10; ++i ) {
        cout << *(int*)chen.chen.SeqList_Get(queue, i) << endl;
    }
    cout << *(int*)chen.chen.SeqList_Delete(queue, 5) << "--:" << *(int*)chen.chen.SeqList_Get(queue, 0) << endl;
    cout << "==" << endl;
    for (int i = 0; i < 9; ++i) {
        cout << *(int*)chen.chen.SeqList_Get(queue, i) << endl;
    }

    chen.SeqQueue_Destroy(queue);



    return 0;
}