C-language bidirectional linked list

Source: Internet
Author: User
Tags prev

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.