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