struct _node
{
int value;
struct _node *next;
struct _node **pre;
};
struct _head
{
struct _node *first;
struct _node **last;
};
{
int value;
struct _node *next;
struct _node **pre;
};
struct _head
{
struct _node *first;
struct _node **last;
};
int main()
{
struct _head head;
head.first = NULL;
head.last = &(head.first);
for(int i = 1; i < 10; i++)
{
struct _node * node = (struct _node *)malloc(sizeof(struct _node));
node->value = i;
node->next = NULL;
node->pre = (&head)->last;
*(head.last) = node;
head.last = &(node->next);
}
struct _node * n;
for(n = head.first; n ; )
{
printf("%d\n",n->value);
n = n->next;
}
head.first = NULL;
head.last = &(head.first);
for(int i = 1; i < 10; i++)
{
struct _node * node = (struct _node *)malloc(sizeof(struct _node));
node->value = i;
node->next = NULL;
node->pre = (&head)->last;
*(head.last) = node;
head.last = &(node->next);
}
struct _node * n;
for(n = head.first; n ; )
{
printf("%d\n",n->value);
n = n->next;
}
//释放free
return 0;
}