1 //This is the C language, but will error, because Len (the current node length)2 //cannot change after insert (insert) and deleted (delete)3 //You cannot use delete because delete is an operator in C + +4 //finally I wrote the change program in C + +, using the reference to change Len's real value5#include <stdio.h>6#include <stdlib.h>7typedefintElementType;8typedefstructNode {9 ElementType data;Ten structNode *pnext;//pointer to next node One}node, *pnode;//here node is equivalent to struct node, and pnode equivalent to struct node* A -Pnode Create_list (intlen); -Pnode Change (Pnode phead,intlen); the voidErgodic (Pnode Phead,intlen); -Pnode Insert (Pnode phead,int*len); - intMain () { -Pnode phead = NULL;//To Create a head node + intLen//used to store the number of active nodes -printf"Please enter the number of nodes:"); +scanf"%d", &len); APhead = Create_list (len);//Create a single-linked list and assign the head pointer of the list to Phead atPnode p;//Create a move pointer to the node you want to access - - -Ergodic (Phead,len);//traversing data output -p = Change (Phead,len);//Modifying the data for a node -Ergodic (Phead,len);//traversing data output inp = insert (Phead,&len);//Insert a node -printf"this time Len is:%d", Len); toprintf"\ nthe insert succeeded \ n"); +Ergodic (Phead,len);//traversing data output - return 0; the } * $ Panax Notoginseng -Pnode Create_list (intLen//here, we use Pnode to return a pointer to a struct type. the { + //Create a linked list A thePnode Phead = (pnode)malloc(sizeof(Node));//assigns a head node for a header that does not hold valid data + //malloc Returns a node, where (struct type pointer) malloc (sizeof (struct name)) -Pnode ptail = Phead;//defines a tail pointer and initializes a $Ptail->pnext = NULL;//Empty the tail node pointer $ - inti; - intVal; the for(i =0; i<len; i++) { -printf"Enter the number of%d nodes:", i +1);Wuyiscanf"%d", &val); thePnode pnew = (pnode)malloc(sizeof(Node)); - //allocating space to the next node WuPnew->data = val;//1. Assign the value to the next node first -Ptail->pnext = pnew;//Pointer field for the new node's pointer field Ptail AboutPnew = NULL;//Place the pointer field for the node empty $Ptail = ptail->pnext;//point the tail pointer +1 to the last node - } - returnPhead;//returns the head pointer of a linked list - } A //++++++++++++++++++++++++++++++ + voidErgodic (Pnode Phead,intLen) { the //traversing data output - Pnode p; $p = phead;//point The Move pointer to the head node the intJ; the for(j =0; j<len; J + +) { thep = p->Pnext; theprintf"the number of%d nodes is:%d\n", (j +1), p->data); - } in } the the //++++++++++++++++++++++++++++++ AboutPnode Change (Pnode phead,intLen) { the //Modifying the data for a node the Pnode p; thep =Phead; + intvalue; -printf"Modify the data for the node \ n"); the intK;Bayi for(k =0; k<len; k++) { thep = p->Pnext; theprintf"enter the data to be modified for%d nodes:", K +1); -scanf"%d", &value); -P->data =value; the } the returnPhead; the } the //+++++++++++++++++++++++++++++ - //inserting Nodes thePnode Insert (Pnode phead,int*Len) { the Pnode p; thep =Phead;94printf"the input is inserted after the first few nodes (not counting the head node):"); the intm; thescanf"%d", &m); the inti;98 for(i =0; i<m; i++) { Aboutp = p->Pnext; - }101Pnode e = (pnode)malloc(sizeof(Node));102E->pnext =NULL;103printf"Please enter a value for this node:");104 intN; thescanf"%d", &n);106E->data =N;107E->pnext = p->Pnext;108P->pnext =e;109len++; the returnPhead;111 } the //+++++++++++++++++++++++++++++++113 //+++++++++++++++++++++++++++++ the //Delete a node thePnode Delete (Pnode phead,intLen) { the Pnode p;117 Pnode q;118p=Phead;119printf"Please enter the node (without the head node) to delete the first number of nodes."); - intK;121scanf"%d",&k);122 inti;123 for(i=0; i<k-1; i++){124P=p->Pnext; the }126Q=p->Pnext;127P->pnext=q->Pnext; - Free(q);129q=NULL; the returnPhead;131}
Comment on the most complete list of C language links and additions and changes