C and Pointers the 12th chapter uses structures and pointers

Source: Internet
Author: User

A linked list is a common data structure in which each node is linked by a chain or pointer, and the program accesses the nodes in the linked list through an indirect pointer.

typedef struct NODE  {    //pointer to the next node     struct node *next;     int value;    }

Single-linked lists can be traversed only one way

Insert in single-linked list: first edition

#include <stdio.h> #include <stdlib.h> #define TRUE 1#define FALSE 0typedef struct Node {struct node *next;int V Alue;} linklist;//assumes the list from small to large sort int Linkinsert (linklist * Current, int value) {//Save the previous node linklist *previous; Linklist *new;//Loop to the appropriate position while (current-> value < value) {previous = Current;current = Current->next;} New = malloc (sizeof (linklist)); if (new = = NULL) {return FALSE;} New->value = Value;new->next = Current;previous->next = New;return TRUE;}


C and Pointers the 12th chapter uses structures and pointers

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.