-
It's not very hard that the tail node next points to null.
You just need while(p->next! =null).
In the middle, p=p->next traverses to the next node, and then uses an n++ count.
That is to say, as long as he knows the information of the linked list header node, he can continue to traverse until the end of the tail node.
This function can be used in many places, such as calculating the length of a linked list, determining whether a linked list is empty, etc.
And you can also pass in the head node pointers of other linked lists to calculate the length of the joins of the multi-linked lists.
-
I don't need other information.,But it's better for a function to execute a single function.,It's messy if there are more functions.,Of course, you can perform other functions depending on how you write it.。
-
Although it can only be used with the type of node it is declared, it is important to know the internal structure of the node.
Count the number of nodes in a singly linked list.
#include "singly_linked_list_"
#include
intsll_count_nodes(struct node *first)
int count;
for(count=0;first!=null;first=first->link){
count+=1;
return count;
If this function is called and passes it a pointer to a node in the middle of the linked list, then it will count the nodes after that node in the linked list.
-
These slaves who test poison are a bunch of bits, the numbers 1 to n correspond to the number of the wine, and all the numbers that bit0 (into binary, the lowest bit is 0bit) is 1, and they are all given to a person to drink; All bit1 is the number of 1, and so on, so that after 20 hours, the number of bits represented by all poisoned slaves is the poisoned bottle of wine.
If the number of wines happens to be to the power of 2, take the bottle with the highest number and do the same for the rest.
For example, 3 bottles of wine, 2 people, numbered 0 and 1, 0 drink the lowest wine with 1, i.e. bottle 1 and bottle 3.
1 drink bit1 is 1 wine, i.e. bottle No. 2 drinks bottle No. 3.
In this way, the result is obvious, the final poisoned bit is 1, and the unpoisoned is 0, and this binary number is the number of the bottle of wine that is to be found.
Solution: Let 2l=20cm, l=10cm
The geometric relationships in the diagram are known. When the rod is under pressure on x and y at any moment, the trajectory of the rod's centroid o is an arc with bo as the radius. >>>More
In order to increase the pressure and thus the friction.
Because each additional point of area is also under pressure, the pressure increases and the friction increases, i.e., the friction at the same point of contact remains the same, but there are more of these points. So the friction has become greater overall. >>>More
First of all, I would like to point out that your second sentence is a wrong sentence and does not add a noun after where. >>>More
The buoyancy of an object is only related to the weight of the discharged liquid. It is believed that the wood floats on the surface of the water and the iron sinks to the bottom. So only the part of the wood below the water level drains the water. >>>More
1 part of blue flower, 2 parts of yellow flower, 3 parts of safflower, blue flower accounts for 1 6 of the total area, yellow flower accounts for 1 3, and safflower accounts for 1 2 >>>More