Simple Application of Two-way circular linked list in C Language

Source: Internet
Author: User

# Include <stdio. h>
# Include <stdlib. h>

Typedef struct Link
{
Struct link * before;
Int data;
Struct link * next;
} Node, * pnode;

Typedef struct real_link
{
Int size;
Struct link head;
Pnode tail;
} List, * plist;

Void initialize (plist mylist)
{
Mylist-> head. Before = NULL;
Mylist-> head. Next = NULL;
Mylist-> head. Data = 0;
Mylist-> tail = NULL;
Mylist-> size = 0;

}
Void creat (plist mylist1)
{
Int I;
Pnode TMP = & mylist1-> head;
While (scanf ("% d", & I ))
{
Pnode p1 = (pnode) malloc (sizeof (node ));
P1-> DATA = I;
Mylist1-> size ++;
P1-> next = NULL;
TMP-> next = p1;
P1-> before = TMP;
TMP = TMP-> next;
Mylist1-> tail = p1;
P1-> next = mylist1-> head. Next; // The End Of The linked list is connected to the header.
Mylist1-> head. Next-> before = p1; // implement Loop

}

Printf ("created successfully \ n ");
}

Void kill (plist mylist, int I)
{
Pnode TMP = NULL;
While (mylist-> size! = 1)
{
Int COUNT = 0;
If (mylist-> size = 6)
{
TMP = mylist-> head. Next;
}
While (count <I)
{
TMP = TMP-> next;
Count ++;
}
Sleep (1 );
Printf ("% d suicide success \ n", TMP-> data );
Pnode ptr1 = TMP-> before;
Pnode ptr2 = TMP-> next;
Free (TMP );
Ptr1-> next = ptr2;
Ptr2-> before = ptr1;
Mylist-> size --;
TMP = ptr2;
}
}

Int main (void ){
List DM;
Initialize (& DM );
Creat (& DM );
Kill (& DM, 23 );

Return exit_success;
}

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.