Job Recruitment Website - Recruitment portal - Is there any experienced craftsman who is proficient in using CNC spinning machines? Recently, I have become obsessed with learning how to program spinning machines.

Is there any experienced craftsman who is proficient in using CNC spinning machines? Recently, I have become obsessed with learning how to program spinning machines.

#include /*Header file containing ma l l o c ( )*/

#include

//① Define linked list data structure

struct node

{

int num;

struct node *next;

};

//Function declaration

struct node *creat();

void print();

main( )< /p>

{

struct node *head;

head=NULL; //②Create an empty table

head=creat(head) ;/*Create a singly linked list*/

print(head);/*Print a singly linked list*/

}

/******* *************************************/

struct node*creat(struct node *head)/*Returns a pointer of the same type as the node*/

{

struct node*p1,*p2;

int i=1 ;

//③Use the malloc () function to apply to the system for allocating a node

p1=p2=(struct node*)malloc(sizeof(struct node));/*New Node*/

printf("Please enter a value. The value should be less than or equal to 0. The value storage address is: p1_ADDR= %d\n",p1);

scanf("% d",&p1->num);/*Enter the value of the node*/

p1->next=NULL;/*Set the pointer of the new node to null*/

while(p1->num>0)/*The value of the input node is greater than 0*/

{

//④Assign the pointer member of the new node to null.

If it is an empty table, connect the new node to the head of the table; if it is a non-empty table, connect the new node to the end of the table;

if(head==NULL)

head=p1; /*Empty table, connect to the header*/

else

p2->next=p1;/*Non-empty table, connect to the end of the table*/

< p> p2=p1;

p1=(struct node*)malloc(sizeof(struct node));/*Next new node*/

i=i+1;

printf("Please enter a value. The value should be less than or equal to 0. The value storage address is: p%d_ADDR= %d\n",i,p2);

scanf(" %d",&p1->num);/*Input the value of the node*/

//⑤ Judge whether there are subsequent nodes to be connected to the linked list, if so, go to 3), otherwise end; < /p>

}

//============== Original program correction part: (Thanks to @daling_datou for the reminder) ========= =======================

free(p1); //The applied one was not entered, so it is released

p1=NULL; //point to null

p2->next = NULL; //reach the end of the table, point to null

printf("End of linked list input (END )\n");

//==================================== ===========

return head;/*Return the head pointer of the linked list*/

}

/**** ***************************************/

void print( struct node*head)/*Get the value of each node of the linked list with head as the head*/

{

struct node *temp;

temp=head ;/*Get the head pointer of the linked list*/

printf("\n\n\nThe value stored in the linked list is:\n");

while(temp!= NULL)/*As long as it is a non-empty list*/

{

printf("%6d\n",temp->num);/*Output the value of the linked list node*/< /p>

temp=temp->next;/*Track the growth of the linked list*/

}

printf("Linked list printing ends!!");

}