The list in the linked list has a custom sort sorting function, which is sorted from large to small by default. However, only the content of the numeric type that can be compared with the size can be used, such as int, float, and double, you need to define the sorting function for struct.
For example:
Define struct:
Typedef
StructNewtreeelem
{
LongNnodeid;
//Node ID
IntNlevel;
//Level
DoubleDsoin;
//Social impact
};
Defines global comparison functions,Note that it must be a global function.:
////Comparison
BoolCompinfo (newtreeelem first, newtreeelem second)
{
If(First. dsoin <= second. dsoin) // sort by size to size. // If You Want To increase by size, change to a value greater
{
Return
False;
}
Else
{
Return
True;
}
}
Define linked list:
List <newtreeelem> listsocialinf
Sort linked lists:
//Sort neighbors by social impact in descending order
Listsocialinf. Sort (compinfo );