Linked List Implementation file C Language

Source: Internet
Author: User

/* Resource_list.c -- linked list implementation file */<br/> # include <stdio. h> <br/> # include <stdlib. h> <br/> # include "cmd_list.h" </P> <p>/* local function declaration */</P> <p> static cmd_list_node * make_node (const cmd_list_item Li1, const implements _list_item li2); </P> <p>/* interface function definition */</P> <p> int initialize_l (list * const PLI) <br/>{< br/> * PLI = NULL; </P> <p> return 1; <br/>}</P> <p> int isempty_l (const list * const PLI) <br/>{< br/> return NUL L = * PLI; <br/>}</P> <p> int insert_l (list * const PLI, const pai_list_item Li1, const pai_list_item li2) <br/>{< br/> pai_list_node * new_node; </P> <p> new_node = make_node (Li1, li2); <br/> If (null = new_node) <br/> return 0; <br/> new_node-> next = * PLI; <br/> * PLI = new_node; </P> <p> return 1; <br/>}</P> <p> int find_l (const list * const PLI, const pai_list_item Li1, const pai_l Ist_item li2) <br/>{< br/> pai_list_node * scan; </P> <p> scan = * PLI; <br/> while (SCAN) <br/>{< br/> If (Li1 = scan-> V & li2 = scan-> W) <br/> return 1; <br/> else <br/> scan = scan-> next; <br/>}</P> <p> return 0; <br/>}</P> <p> int delete_l (list * const PLI, const pai_list_item Li1, const pai_list_item li2) <br/> {<br/> pai_list_node * scan, * temp; </P> <p> If (isempty_l (PLI) <br/> Return 0; <br/> scan = * PLI; <br/>/* There is nly one node in the list and hit the target */<br/> If (null = scan-> next & Li1 = scan-> V & li2 = scan-> W) <br/>{< br/> free (SCAN); <br/> * PLI = NULL; <br/> return 1; <br/>}< br/> while (scan-> next & scan-> next-> V! = Li1 & scan-> next-> W! = Li2) <br/> scan = scan-> next; <br/> If (scan-> next) <br/> {<br/> temp = scan-> next; <br/> scan-> next = temp-> next; <br/> free (temp ); <br/> return 1; <br/>}< br/> else <br/> return 0; <br/>}</P> <p> void traversal_l (const list * const PLI, void (* pfun) (const pai_list_node * const PLN )) <br/> {<br/> pai_list_node * scan; </P> <p> scan = * PLI; <br/> while (SCAN) <br/>{< br/> (* pfun) (SCAN); <br/> scan = scan-> next; <br/>}</P> <p> void release_l (const list * const PLI) <br/>{< br/> pai_list_node * scan, * temp; </P> <p> scan = * PLI; <br/> while (SCAN) <br/> {<br/> temp = scan; <br/> scan = scan-> next; <br/> free (temp ); <br/>}</P> <p>/* local function definition */</P> <p> static performance_list_node * make_node (const performance_list_item Li1, const pai_list_item li2) <br/>{< br/> pai_list_node * new_node; </P> <p> new_node = (pai_list_node *) malloc (sizeof (pai_list_node )); <br/> If (null = new_node) <br/> return NULL; <br/> new_node-> V = Li1; <br/> new_node-> W = li2; </P> <p> return new_node; <br/>}

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.