void bubble_sort (struct account * head)
{
Int I, count=0, num.//count records list the number of nodes, num of inner circulation,
Struct account * p, * q, * tail;//create a three pointer, bubble sort
Struct account * add_head=NULL;
Add_head=(struct account *) malloc (LEN);//the three lines up and down the main is to add a head node, make the first line of data involved in the bubbling
Add_head - & gt; Next=head;
P=add_head;
While (p - & gt; Next!=NULL)
{
count++;
P=p - & gt; Next;
}
for(i=0; i{
Num=count - I - 1;
Q=add_head - & gt; Next;//make q point to the first node
P=q - & gt; Next;//after make p points to a node
Tail=add_head;//let the tail always points to a node before the q, convenient exchange, also make the operation and on to the next step
While (num -)
{
If (STRCMP (q - & gt; The name, p - & gt; Name) & gt; 0)
{
Q - & gt; Next=p - & gt; Next;//let q next next to p, skip p
P - & gt; Next=q;//p again next to q
Tail - & gt; Next=p;//the last the head node Pointers p
}
Tail=tail - & gt; Next;
Q=tail - & gt; Next;
P=q - & gt; Next;
}
}
Mem_print (add_head - & gt; Next);//directly next to it is not sweet, waste I've been racking my brains!!!!!!!!!!!!!!!
}
CodePudding user response:
This is why some data structure teaching materials like head nodes rather than the head pointer,