C++ 为循环队列实现偏移量排队方法

C++ 为循环队列实现偏移量排队方法,c++,data-structures,queue,circular-list,C++,Data Structures,Queue,Circular List,我目前正在从事一个模拟环岛周围交通流的项目,为此,我构建了两个数据结构“LinearQueue”和“CircularQueue”,这两个数据结构都是使用链表结构节点实现的 我的CircularQueue类具有排队和退队的方法,这是任何循环队列类型结构的典型特征,但是由于我有4个(实际上是8条双向的道路)LinearQueue对象,它们需要以CircularQueue(环岛)的四分之一容量间隔链接对象我需要一种方法将项目排列在队列后部或前部的偏移位置,我不确定如何正确实现这一点 以下是我的Circ

我目前正在从事一个模拟环岛周围交通流的项目,为此,我构建了两个数据结构“LinearQueue”和“CircularQueue”,这两个数据结构都是使用链表结构节点实现的

我的CircularQueue类具有排队和退队的方法,这是任何循环队列类型结构的典型特征,但是由于我有4个(实际上是8条双向的道路)LinearQueue对象,它们需要以CircularQueue(环岛)的四分之一容量间隔链接对象我需要一种方法将项目排列在队列后部或前部的偏移位置,我不确定如何正确实现这一点

以下是我的CircularQueue::enqueue(类型)方法:

其中currentSize和maxCapacity是整数字段变量,分别存储当前已填充队列大小和最大允许容量。前后是指向以下节点结构的指针:

struct CQNode {
    Type head;
    CQNode* tail;

    CQNode() {
        //this->head = 0;
        this->tail = 0;
    }

    CQNode(Type& head, CQNode* tail = 0) {
        this->head = head;
        this->tail = tail;
    }

};
类型是类模板中给定的类型名

我的偏移量排队方法目前只有以下内容:

Type enqueue(Type& item, int offset) {

    // if the offset given is 0, then simply call overloaded enqueue with just the item
    if (offset == 0) {
        return enqueue(item);
    }

    Type* itemPtr = &item;

    if (itemPtr == 0) {
        throw std::invalid_argument("Item to be enqueued onto Circular Queue cannot be null!");
    }

    if (this->currentSize == this->maxCapacity) {
        throw CircularQueueException("Circular queue is full, cannot enqueue any more items.");
    }

}
我只是在努力寻找从何处开始使用该方法,因为我可以看到空指针在循环队列中以不同偏移量排队和出列对象时存在很多问题

Type enqueue(Type& item, int offset) {

    // if the offset given is 0, then simply call overloaded enqueue with just the item
    if (offset == 0) {
        return enqueue(item);
    }

    Type* itemPtr = &item;

    if (itemPtr == 0) {
        throw std::invalid_argument("Item to be enqueued onto Circular Queue cannot be null!");
    }

    if (this->currentSize == this->maxCapacity) {
        throw CircularQueueException("Circular queue is full, cannot enqueue any more items.");
    }

}