#include<bits/stdc++.h>
using namespace std;
struct Node{
int reg;
string name;
double cg;
Node*next;
};
Node*InsertAtBegin(Node*root,int reg,string name,double cg)
{
Node*newnode=new Node();
newnode->reg=reg;
newnode->name=name;
newnode->cg=cg;
newnode->next=NULL;
if(root==NULL)
{
root=newnode;
return root;
}
else
{
newnode->next=root;
root=newnode;
return root;
}
}
Node*InsertAtPos(Node*root,int reg,string name,double cg,int pos)
{
if(pos==0)
{
root=InsertAtBegin(root,reg,name,cg);
}
else
{
Node*newnode=new Node();
newnode->reg=reg;
newnode->name=name;
newnode->cg=cg;
newnode->next=NULL;
Node*currnode;
currnode=root;
for(int i=1;i<pos;i++)
{
currnode=currnode->next;
}
newnode->next=currnode->next;
currnode->next=newnode;
}
return root;
}
Node*InsertAtEnd(Node*root,int reg,string name,double cg)
{
Node*newnode=new Node();
newnode->reg=reg;
newnode->name=name;
newnode->cg=cg;
newnode->next=NULL;
if(root==NULL)
{
root=newnode;
return root;
}
Node*currnode;
currnode=root;
while(currnode->next!=NULL)
{
currnode=currnode->next;
}
currnode->next=newnode;
return root;
}
Node*SortedInsert(Node*root,int reg,string name,double cg)
{
Node*newnode=new Node();
newnode->reg=reg;
newnode->name=name;
newnode->cg=cg;
newnode->next=NULL;
Node*currnode,*prevnode;
currnode=root;
prevnode=NULL;
if(root==NULL)
{
root=newnode;
return root;
}
if(reg<root->reg || name<root->name || cg<root->cg)
{
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;
}
int Search(Node*root,int reg,string name,double cg)
{
int pos=0;
Node*currnode;
currnode=root;
while(currnode!=NULL)
{
if(currnode->reg==reg && currnode->name==name && currnode->cg==cg)
{
return pos;
}
else
{
currnode=currnode->next;
pos++;
}
}
return -1;
}
Node*Delete(Node*root,int reg,string name,double cg)
{
Node*currnode,*prevnode;
currnode=root;
prevnode=NULL;
while(currnode!=NULL)
{
if(currnode->reg!=reg && currnode->name!=name && currnode->cg!=cg)
{
prevnode=currnode;
currnode=currnode->next;
}
if(currnode==root)
{
root=root->next;
delete(currnode);
}
else
{
prevnode->next=currnode->next;
delete(currnode);
}
break;
}
return root;
}
void Print(Node*root)
{
Node*currnode;
currnode=root;
while(currnode!=NULL)
{
cout<<"reg:"<<currnode->reg<<" "<<"name:"<<currnode->name<<" "<<"cg;"<<currnode->cg<<" ";
currnode=currnode->next;
}
cout<<endl;
}
int main()
{
Node*root=NULL;
root=InsertAtBegin(root,101,"tu",4.00);
root=InsertAtBegin(root,108,"ku",3.90);
root=InsertAtBegin(root,102,"lu",3.91);
Print(root);
root=InsertAtPos(root,100,"mu",3.98,0);
root=InsertAtPos(root,104,"nu",3.55,3);
Print(root);
root=InsertAtEnd(root,109,"su",3.24);
root=InsertAtEnd(root,122,"cu",3.17);
Print(root);
cout<<"Position of 102,lu,3.91:"<<Search(root,102,"lu",3.91)<<endl;
cout<<"Position of 123,ou,1.89:"<<Search(root,123,"ou",1.89)<<endl;
root=Delete(root,104,"nu",3.55);
root=Delete(root,135,"au",2.3);
Print(root);
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKc3RydWN0IE5vZGV7CmludCByZWc7CnN0cmluZyBuYW1lOwpkb3VibGUgY2c7Ck5vZGUqbmV4dDsKfTsKTm9kZSpJbnNlcnRBdEJlZ2luKE5vZGUqcm9vdCxpbnQgcmVnLHN0cmluZyBuYW1lLGRvdWJsZSBjZykKewpOb2RlKm5ld25vZGU9bmV3IE5vZGUoKTsKbmV3bm9kZS0+cmVnPXJlZzsKbmV3bm9kZS0+bmFtZT1uYW1lOwpuZXdub2RlLT5jZz1jZzsKbmV3bm9kZS0+bmV4dD1OVUxMOwppZihyb290PT1OVUxMKQp7CnJvb3Q9bmV3bm9kZTsKcmV0dXJuIHJvb3Q7Cn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