所以我试图创建一个带有链接列表的队列,但是我的插件(充当push_back)和我的擦除(充当pop_front)显然是插入和擦除没有&想要按照自己的意愿工作。
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
using namespace std;
template <class T>
struct Node {
T value;
Node<T> *next;
Node<T> *prev;
Node() : value(T()), next(NULL), prev(NULL) {}
Node(T v) : value(v), next(NULL), prev(NULL) {}
T getValue() { return value; }
void setValue(T v) { value = v; }
};
template <class T>
class LinkedList {
private:
Node<T> *header;
public:
LinkedList() {
header = new Node<T>();
header->next = header;
header->prev = header;
}
~LinkedList() {
while (header->next != header->next)
delete header;
}
void insert(T n) {
Node<T> *newNode = new Node<T>(n);
newNode->prev = header;
newNode->next = header->next;
newNode->next->prev = newNode;
header->next = newNode;
}
void erase() {
header->next->prev->next = header->next->next;
header->next->next->prev = header->next->prev;
delete header->next;
}
Node<T> *begin() { return header->next; }
Node<T> *end() { return header; }
};
#endif // LINKEDLIST_H