Linked list

xiaoxiao2021-03-06  71

#include #include

#define ok 1 # Define error 0

TypedEf Int EleMTYPE, STATUS

Typedef struct lnot {elemType data; // Data domain struct lnode * next; // Reflector Domain} lnote, * linklist;

STATUS LISTINSERT_L (Linklist L, ELEMTYPE E) {// Insert element E into an orderly linked list L, so it is still orderly linklist pone = null; Pone = (LNODE)); Pone-> Data = E; Pone-> Next = NULL; if (l-> next == null) {l-> next = pone; return 1;} do {if (E next-> data) {Pone- > next = l-> next; l-> next = pone; return 1;} l = l-> next;} while (l-> next! = null); l-> next = pone; return 0;}

Void Createlist_L (Linklist & l) {// New Link list, including the establishment of the header, the input value, and the call to the ListInsert_l function. L = (linklist) malloc (sizeof (linklist)); l-> next = null; elemType E;

While (1) {scanf ("% d", & e); if (e <0) Break; Else ListInsert_L (L, E);}}

Void delete_between (Linklist L, INT MINK, INT MAXK) {// Remove the chain mesh value of MINK, Maxk Niode IF (L! = null) {LinkList Pone = Null, PTWO = NULL, PCLIENT1 = NULL, PCLIENT2 = NULL; while (l! = Null) {if (l-> next-> data> mink) {pone = L; Break;} l = l-> next;} while (l! = Null) {if (L -> Next-> Data> maxk) {PTWO = L-> next; break;} l = l-> next;}

IF ((Pone-> Data - PTWO-> DATA)> = 0) {Printf ("/ N has not been deleted node, please pay attention to the sequencing and size of the two numbers! / n"); Return;} PClient1 = Pone-> next; pClient2 = pClient1-> next; pone-> next = ptwo; while (pClient2! = ptwo) {free (pClient1); pClient1 = pClient2; pClient2 = pClient2-> next;} free (pClient1); Else {Printf ("THE LIST IS Empty!"); Return;}} Void Displist_L (LinkList L) {// Access each node in the Link table - Display Node's value IF ((L) = L-> Next)! = Null) While (l! = Null) {printf ("% d / n", l-> data); l = l-> next;} else {printf ("the list is empty ! "); Return;}}

Void main (void) {linkList L, Client; ElemType Mink, Maxk

Printf ("Please enter a few positive integers, ending with a negative number:"); CreateList_L (L); Displist_L (L);

Client = L; while (client! = null) {Printf ("% d / n", client); client = client-> next;} printf ("% d", sizeof (linklist)); printf ("Please enter Two from small to large integers: "); Scanf ("% D% D ", & mink, & maxk; delete_between (L, Mink, Maxk); Displist_L (L);}

转载请注明原文地址:https://www.9cbs.com/read-109642.html

New Post(0)