#include <iostream>
using namespace std;
struct link
{
double num;
link* next;
link* front;
};
int main()
{
link* p, * head;
p = head = new link;
for (int i = 0; i < 5; i++)
{
p->num = i;
p->next = new link;
p->next->front = p;
p = p->next;
}
p = head;
for (int i = 0; i < 5; i++)
{
cout << p->num << endl;
p = p->next;
}
p = p->front;
for (int i = 4; i >= 0; i--)
{
cout << p->num << endl;
p = p->front;
}
p = head;
link* t = new link;
t->num = 10;
p->next->front = t;
t->next = p->next;
p->next = t;
t->front = p;
p = head;
for (int i = 0; i < 6; i++)
{
cout << p->num << endl;
p = p->next;
}
p = head;
for (int i = 0; i < 6; i++)
{
if (p->num == 2)
{
p->front->next = p->next;
p->next->front = p->front;
delete p;
break;
}
p = p->next;
}
p = head;
for (int i = 0; i < 5; i++)
{
cout << p->num << endl;
p = p->next;
}
link* a = head;
p = head;
for (int i = 0; i < 5; i++) {
p = p->next;
delete a;
a = p;
}
}
|