Data structure---C-language implementation of circular single-link list operation

Source: Internet
Author: User

Implementation of ========= Xin Yang ========================////loop single-link list # include <stdio.h> #include <stdlib.h> typedef int                    elemtype;//defines the node type typedef struct node{elemtype data;            struct Node *next;    }node,*linkedlist;int count = 0;//1, the initialization of the single-loop list LinkedList init_circular_linkedlist () {Node *l;      L = (node *) malloc (sizeof (node));    if (L = = NULL) printf ("Application memory space failed \ n");                    L->next = L;    }//2, the establishment of the circular single-link list linkedlist creat_circular_linkedlist () {Node *l;       L = (node *) malloc (sizeof (node));                       L->next = L;    Node *r;                                R = L;                             Elemtype x;        while (scanf ("%d", &x)) {if (x = = 0) break;count++;        Node *p;            p = (node *) malloc (sizeof (node));                              P->data = x;                          R->next = p;    r = P;     } r->next = L;   return L; }//4, the insertion of a circular single-linked list, inserting an element of x in the first position of the loop list LinkedList InserT_circuler_linkedlist (LinkedList l,int i,elemtype x) {Node *pre;    Pre = L;    int tempi = 0;                      for (tempi = 1; tempi < i; tempi++) Pre = pre->next;                                     Node *p;     p = (node *) malloc (sizeof (node));     P->data = x;    P->next = pre->next;    Pre->next = p;                           return L;                        }//5, delete the circular list, delete the element with the value x in the circular list LinkedList delete_circular_linkedlist (LinkedList l,elemtype x) {Node *p,*pre;    p = l->next;         while (P->data! = x) {pre = P;    p = p->next;                } Pre->next = p->next;    Free (p); return L;}    int main () {int i; LinkedList list, start;printf ("Please enter the data for the circular single-linked list, end with 0!     \ n "); List = Creat_circular_linkedlist ();p rintf ("The elements of the looping list are: \ n"); for (start = list->next; start! = NULL; start = start-> Next) {if (count== 0) {break;}            printf ("%d", start->data); count--;} printf ("\ n");  return 0;}



Data structure---C-language implementation of circular single-link list operation

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.