С++.Списки. Двусвязный кольцевой список. Нужно проверить правильность функций
Моя первая практика со списками.
Задача: написать реализацию функций.
Я сам написал, сколько смог. Но все равно толком не работает. Ошибок, по-любому, много, за это извините. Внимание! Это Кольцевой двусвязный список.
#include <iostream>
using namespace std;
struct Double_node{
int val;
Double_node* next;
Double_node* prev;
Double_node() {}
Double_node(int x, Double_node* n = NULL, Double_node* p = NULL) {
val = x;
next = n;
prev = p;
}
};
class Double_list {
private:
Double_node* tail= nullptr;
int sz=1;
public:
Double_list() {
tail = new Double_node();
tail->next = tail;
tail->prev = tail;
}
Double_list(int x) {
Double_node* t = new Double_node();
t->next = t;
t->prev = t;
t->val = x;
}
~Double_list() {
Double_node* cur = tail->next;
while (cur != tail)
{
Double_node* t = cur->next;
delete cur;
cur = t;
}
}
void push_front(int x) {
Double_node*cur = tail -> next;
tail->next = new Double_node(x,cur,tail);
}
void push_back(int x) {
Double_node* cur = tail->prev;
tail->prev = new Double_node(x, tail, cur);
}
void pop_back() {
Double_node* cur = tail->prev->prev;
delete tail->prev;
tail->prev = cur;
cur->next = tail;
}
void pop_front() {
Double_node* cur = tail->next->next;
delete tail->next;
tail->next = cur;
cur->prev = tail;
}
bool empty() {
if (tail->next = tail) return true;
else return false;
}
int size() {
Double_node* cur = tail->next;
while (cur != tail)
{
sz++;
cur = cur->next;
}
return sz;
}
void clear() {}
int& front() { return tail->next->val; }
int& back() { return tail->prev->val; }
void print() {
Double_node* cur = tail->next;
while (cur != tail)
{
cout << cur->val << endl;
cur = cur->next;
}
}
};
int main()
{
Double_list a;
a.push_back(111);
a.push_back(222);
a.print();
return 0;
}