#include<bits/stdc++.h>
using namespace std;
struct Node{
int reg;
string name;
float cg;
Node*next;
};
Node*SortedInsert(Node*root,int reg,string name,float cg)
{
Node*newnode=new Node();
newnode->next=NULL;
newnode->reg=reg;
newnode->name=name;
newnode->cg=cg;
Node*currnode,*prevnode;
currnode=root;
prevnode=NULL;
if(root==NULL)
{
root=newnode;
return root;
}
if(reg<currnode->reg)
{
newnode->next=root;
root=newnode;
return root;
}
while(currnode!=NULL)
{
if(currnode->reg<reg)
{
prevnode=currnode;
currnode=currnode->next;
}
else
{
prevnode->next=newnode;
newnode->next=currnode;
return root;
}
}
prevnode->next=newnode;
newnode->next=NULL;
return root;
}
void Print(Node*root)
{
Node*currnode;
currnode=root;
while(currnode!=NULL)
{
cout<<"reg:"<<currnode->reg<<"name:"<<currnode->name<<"cg:"<<currnode->cg<<endl;
currnode=currnode->next;
}
cout<<endl;
}
int main()
{
Node*root=NULL;
root=SortedInsert(root,98,"vu",3.45);
root=SortedInsert(root,110,"Xu",2.78);
Print(root);
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKc3RydWN0IE5vZGV7CmludCByZWc7CnN0cmluZyBuYW1lOwpmbG9hdCBjZzsKTm9kZSpuZXh0Owp9OwoKCk5vZGUqU29ydGVkSW5zZXJ0KE5vZGUqcm9vdCxpbnQgcmVnLHN0cmluZyBuYW1lLGZsb2F0IGNnKQp7Ck5vZGUqbmV3bm9kZT1uZXcgTm9kZSgpOwpuZXdub2RlLT5uZXh0PU5VTEw7Cm5ld25vZGUtPnJlZz1yZWc7Cm5ld25vZGUtPm5hbWU9bmFtZTsKbmV3bm9kZS0+Y2c9Y2c7Ck5vZGUqY3Vycm5vZGUsKnByZXZub2RlOwpjdXJybm9kZT1yb290OwpwcmV2bm9kZT1OVUxMOwppZihyb290PT1OVUxMKQp7CnJvb3Q9bmV3bm9kZTsKcmV0dXJuIHJvb3Q7Cn0KaWYocmVnPGN1cnJub2RlLT5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