Professional Documents
Culture Documents
if(head==NULL)
{
head=n;
tail=n;
}
else
{
n->next=head;
head=n;
}
}
node* getNode(string n) {
node* temp = head, * pretemp = head;
while (temp != NULL) {
if (temp->name == n) {
return pretemp;
}
pretemp = temp;
temp = temp->next;
}
}
void inserBeforeName(node* s, node x) {
node* n = new node;
n->name=x.name;
n->reg=x.reg;
n->gpa=x.gpa;
n->next = s->next;
s->next = n;
}
void display()
{
float gp;
cout<<"Enter gpa :"<<endl;
cin>>gp;
node *temp = head;
while(temp != NULL)
{
if(temp->gpa>gp)
{
ptr = ptr->next;
}
}
};
int main()
{
list obj;
node obj1;
char ch;
int choice;
int val;
do{
cout<<"Press 1 to insert at front:"<<endl;
cout<<"Press 2 to insert at end:"<<endl;
cout<<"Press 3 to insert at middle:"<<endl;
cout<<"Press 4 sort:"<<endl;
cout<<"Press 5 to display:"<<endl;
cin>>choice;
switch(choice)
{
case 1:
{
cout<<"Enter Name:"<<endl;
cin>>obj1.name;
cout<<"Enter regno:"<<endl;
cin>>obj1.reg;
cout<<"Enter gpa:"<<endl;
cin>>obj1.gpa;
obj.insert_front(obj1);
break;
}
case 2:
{
cout<<"Enter Name:"<<endl;
cin>>obj1.name;
cout<<"Enter regno:"<<endl;
cin>>obj1.reg;
cout<<"Enter gpa:"<<endl;
cin>>obj1.gpa;
obj.insert_end(obj1);
break;
}
case 3:
{
cout<<"Enter Name:"<<endl;
cin>>obj1.name;
cout<<"Enter regno:"<<endl;
cin>>obj1.reg;
cout<<"Enter gpa:"<<endl;
cin>>obj1.gpa;
string nam;
string n;
cout<<"Enter Name to insert before sudent:"<<endl;
cin>>n;
obj.inserBeforeName(obj.getNode(n),obj1);
break;
}
case 4:
{
obj.sort();
break;
}
case 5:
{
obj.display();
break;
}
default:
cout<<"wrong input:"<<endl;
break;
}
cout<<"Press y/Y to enter more entries:"<<endl;
cin>>ch;
}while(ch=='y'|| ch=='Y');
return 0;
}