1, first, the initial value of the list to the user's input
2, according to a user's input, prints out the list after initialization
3, users continue to enter the value of looking
4, according to this value in the list to find the data field is the value of the node, and counted, and returns the number of nodes satisfying the condition
1 / * Returns the number of nodes a specific data field value * / 2 . 3 #include <stdio.h> . 4 #include <stdlib.h> . 5 . 6 // linked list node structure . 7 typedef struct Link { . 8 int Data; . 9 struct Link * Next; 10 } Link; . 11 12 is // list initialization 13 is Link * initByTailInsert () { 14 Link PHEAD * = NULL; // Create a head pointer 15 Link first_node = * (* Link) the malloc ( the sizeof (Link) ); // create the first node 16 // first node to initialize . 17 first_node-> = Data . 1 ; 18 is first_node-> Next = NULL; . 19 PHEAD = first_node; // head pointer points to the first node 20 is 21 is int Input_Data = 0 ; // user input the value of 22 is 23 is // End inserted assignment 24 the printf ( " Please enter the four integers: " ); 25 for ( int I = 2 ; I < . 6 ; I ++ ) { 26 is Link * new_node = (Link *) the malloc ( the sizeof ( Link));// request a new node 27 28 // new_node-> Data = I; 29 Scanf ( " % D " , & Input_Data); 30 new_node-> Data = Input_Data; 31 is 32 new_node-> Next = NULL; 33 is first_node- > Next = new_node; // first node pointer field point to the new node application 34 is first_node = new_node; // after the first shift node 35 } 36 37 [ // the printf ( "head pointer value is:% D \ n-", phead-> Data); // . 1 38 is return PHEAD; //Will point to the first node returns the head pointer 39 } 40 41 is 42 is 43 is void ShowLink (Link * PHEAD) { 44 is Link * tmp = PHEAD; // head from pointer tmp, tmp is a head pointer 45 // long tmp pointer to the next node is not Null, the output statement is executed. 46 is the while (tmp =! NULL) { 47 the printf ( " % D " , tmp-> Data); 48 tmp = tmp-> Next; 49 } 50 the printf ( " \ n- " ); 51 is } 52 is 53 is //Returns the field value number of particular data node 54 is int COUNT (* Link PHEAD, int value) { 55 Link * tmp = PHEAD; 56 is int COUNT = 0 ; 57 is the while (tmp =! NULL) { 58 IF (tmp-> == Data value) { 59 COUNT ++ ; 60 } 61 is tmp = tmp-> Next; 62 is } 63 is return COUNT; 64 } 65 66 void main () { 67 // initialization list (1,2,3,4) 68 the printf ( " initialization list is: \ n- " ); 69 Link * = initByTailInsert PHEAD (); // create a header pointer, the head pointer is initialized and give the 70 ShowLink (PHEAD); 71 is int value = 0 ; 72 the printf ( " Please enter the search elements: " ); 73 is Scanf ( " % d " , & value); 74 the printf ( " data field is the number of nodes is% d:% d \ n- " , value, COUNT (PHEAD , value)); 75 76 }