Inserting an element into a linked list can be divided into three cases:
1, at the time of the node
2. Any position in the middle of the linked list
3, in the last position of the list, you can also think that this situation is appended (this is left to append to the time to achieve)
The following is the implementation of the Code
SN *insert_s_node (SN *head)/* The parameters passed in are inserted into the list of head pointers */{SN *insert_node=null, *dest_node = null;/* Insert_node is the node in the new linked list to be made Dest_node is the node to be inserted */int32 OSM = 1, i32i = 0, flag = 0; Dest_node = (sn*) malloc (sizeof (SN)), Insert_node = HEAD;OSM = osm_printf ("Enter location to insert:");D est_node->sensor_rating = s Canf_for (); /* Enter the inserted ordinal */i32i = GetChar ();/* Eliminate the effect of carriage return */if (0 > dest_node->sensor_rating)/* prevent input of less than 0 */{osm = osm_printf ("Please Lose into a number greater than 0 \ n "); ELSE{OSM = osm_printf ("Enter the element to insert:");/* The element that is inserted */if (NULL! = Dest_node->sensor_title) {Gets (dest_node->sensor_title );/* Input inserted element */}/* traverse to position to insert */while (insert_node->next! = NULL) {insert_node = insert_node->next;if (0 = = flag) {if (dest_node->sensor_rating = = insert_node->next->sensor_rating)/* Determine equality */{dest_node->next = Insert_ node->next;/* start Execution Q->next = P->next Q->next = P */insert_node->next = Dest_node;flag = 1;/* Set Flag */Insert_N Ode = Dest_node->next;}} if (1 = = flag) {insert_node->sensor_rating++;}}} ReTurn head;}
This can be achieved in the middle of the insertion
But there was a problem when the implementation was inserted at the head node.
This problem is not taken into account in the case of the head node being inserted
Three cases where a node is inserted in a linked list