template<class T>
struct Node
{
Node()
{
this->next = nullptr;
this->value = 0;
};
Node(T a)
{
this->next = nullptr;
this->value = a;
}
Node * next;
T value;
};
template<class T>
struct CircleList
{
Node<T>* head;
int count = 0;
CircleList()
{
head = new Node<T>;
head->value = 0;
this->count = 0;
}
~CircleList()
{
Node<T> * temp = head->next;
while (this->count != 1)
{
temp = this->erase(temp);
}
delete head;
}
void Insert(T data)
{
Node<T>* p = new Node<T>(data);
Node<T> * temp = head;
for (int i = 0; i < count; i++)
{
temp = temp->next;
}
temp->next = p;
temp->next->next = head->next;
count++;
}
Node<T>* erase(Node<T> *p)
{
p->value = p->next->value;
Node<T> * temp = p->next;
p->next = p->next->next;
delete temp;
count--;
return p;
}
};
循环链表与约瑟夫环
最新推荐文章于 2024-08-22 19:20:50 发布