typedef int ELEMTYPE;
typedef struct _NODE
{
Elemtype value;
struct _node* pnext;
struct _node* prev;
}node, *pnode;
Create a doubly linked list
Pnode create_double_list (int count)
{
Pnode pn = NULL;
Pnode PB = NULL;
Pnode Phead = (pnode) malloc (sizeof (node));
printf ("Please enter a value for the 1th node:");
scanf ("%d", &phead->value);
if (count = = 1)
{
Phead->pnext = Phead->prev = Phead;
return phead;
}
Else
{
int i = 0;
//Phead->pnext = Phead->prev = NULL;
PN = Phead;
for (i = 1; i < count; ++i)
{
PB = (pnode) malloc (sizeof (node));
printf ("Please enter the value of%d nodes:", (i + 1));
scanf ("%d", &pb->value);
Pn->pnext = PB;
Pb->prev = PN;
PN = PB;
}
Pn->pnext = Phead;
Phead->prev = PN;
return phead;
}
}
Positive sequence traversal
void Printf_next_list_value (Pnode pnode)
{
int i = 0;
Pnode pn = Pnode;
printf ("The result of a positive sequence traversal is:");
while (I < g_count)
{
if (Pn->pnext = = PN)
{
printf ("%3d", Pn->value);
}
if (pn->pnext! = PN)
{
printf ("%3d", Pn->value);
PN = pn->pnext;
}
i++;
}
printf ("\ n");
}
This article is from the "Linux_woniu" blog, make sure to keep this source http://llu1314.blog.51cto.com/5925801/1965327
C-language bidirectional linked list