# 操作说明

## Define

//定义代码示例
class Node
{
public:
int  data;
Node* next;
Node* prior;
public:
Node()                //构造函数初始化指针数据成员
{
next = nullptr;
prior = nullptr;
data = -1;
}
};


## Creat

//创建代码示例
void Fill(Node *&A)
{   //输入长度
int N;
cin >> N;
//插入头结点
Node* p;
p = new Node;
p->prior = p;
p->next = p;
A = p;
Node* temp = A;
for (int i = 0; i < N; i++)
{
Node* p;
p = new Node;
p->data = rand();       //随机生成数据
temp->next = p;
A->prior = p;
p->prior = temp;
p->next = A;
temp = temp->next;
}
}


## Insert

//插入代码示例
bool Insert(Node* A)
{
if (A->next==A)
return false;  //判断是否为空
int place;
cin >> place;
Node* temp = A;
int length = 0;
while (temp->next != A)
{
temp = temp->next;
++length;
}
if (place > length)
return false;    //判断是否超出长度
Node* p;
p = new Node;
p->data = 0;               //插入值为0
for (int i = 0; i < place - 1; i++)
A = A->next;                     //找到插入位置
p->next = A->next;
p->prior = A;
A->next->prior = p;
A->next = p;
return true;
}


## Delete

//删除代码示例
bool Delete(Node* A)
{
if (A->next==A)
return false;  //判断是否为空
int place;
cin >> place;

Node* temp = A;
int length = 0;
while (temp->next != A)
{
temp = temp->next;
++length;
}
if (place > length)
return false;             //判断是否超出长度
for (int i = 0; i < place; i++)
A = A->next;
A->next->prior = A->prior;     //指针操作
A->prior->next = A->next;
delete A;                 //释放内存
return true;
}


## Inverse

//转置代码示例
bool Inverse(Node*& A)
{
if (A->next==A)
return false;  //判断是否为空
Node* Bejin = A->next;
Node* Last = A->prior;       //指针赋值
int n;
while (Last->next!=Bejin&&Last!=Bejin)    //"相遇"时停止
{
n = Last->data;
Last->data = Bejin->data;
Bejin->data = n;
Last = Last->prior;
Bejin = Bejin->next;
}
return true;
}


## Output

//输出代码示例
bool Output(Node* List)
{
if (List->next == List)
return false;         //判断是否为空
Node* temp = List;
temp = temp->next;
while (temp != List)            //中止判断
{
cout << temp->data << ",";
temp = temp->next;
}
cout << "\n";
}


# 运行展示

## 主函数

int main()
{
srand(time(0));
Node* List;
List = new Node;
Fill(List);
Output(List);
Insert(List);
Output(List);
Delete(List);
Output(List);
Inverse(List);
Output(List);
Node* test1 = List->prior;   //清空内存
while (List != test1)
{
Node* temp = List->next;
delete List;
List = temp;
}
delete List;
return 0;
}


07-17

04-20
01-08
08-30 9117
09-25 686
05-21 1297
03-14 986
09-22 148
02-28 3822