C19 updated entire code
This commit is contained in:
parent
ceef4d3713
commit
f9b05b7fa9
@ -1,60 +1,339 @@
|
|||||||
// This code creates a linked list to store PRN and names of n number of students.
|
#include<iostream>
|
||||||
// We're not sure if there's anything more to it. For now, it only stores and displays.
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class node {
|
class student
|
||||||
int roll;
|
{
|
||||||
string name;
|
int roll;
|
||||||
node *next;
|
string name;
|
||||||
|
student *next;
|
||||||
public:
|
public:
|
||||||
static node* create();
|
student* create();
|
||||||
void display(node* head);
|
void display(student *head);
|
||||||
|
student* beg_add(student *head);
|
||||||
|
student* end_add(student *head);
|
||||||
|
student* btwn_add(student *head);
|
||||||
|
student* beg_del(student *head);
|
||||||
|
student* end_del(student *head);
|
||||||
|
student* btwn_del(student *head);
|
||||||
|
student* total(student *head);
|
||||||
|
student* con(student *head,student *head1);
|
||||||
};
|
};
|
||||||
|
|
||||||
node* node::create() {
|
student* student::create()
|
||||||
int total;
|
{
|
||||||
node *head=NULL;
|
int n;
|
||||||
node* point=NULL;
|
student *head,*p;
|
||||||
cout<<"Total number of students are:\t";
|
head = NULL;
|
||||||
cin>>total;
|
cout<<"Enter number of members: ";
|
||||||
|
cin>>n;
|
||||||
|
for(int i = 0; i<n; i++)
|
||||||
|
{
|
||||||
|
if(head == NULL)
|
||||||
|
{
|
||||||
|
head = new student;
|
||||||
|
cout<<"\nEnter prn of president: ";
|
||||||
|
cin>>head->roll;
|
||||||
|
cout<<"Enter name of president: ";
|
||||||
|
cin>>head->name;
|
||||||
|
head->next = NULL;
|
||||||
|
p = head;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p->next = new student;
|
||||||
|
p = p->next;
|
||||||
|
cout<<"\nEnter prn of member: ";
|
||||||
|
cin>>p->roll;
|
||||||
|
cout<<"Enter name of member: ";
|
||||||
|
cin>>p->name;
|
||||||
|
p->next = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return head;
|
||||||
|
|
||||||
for (int i=0; i<total; i++) {
|
}
|
||||||
if (head==NULL) {
|
|
||||||
head = new node;
|
void student::display(student *head)
|
||||||
cout<<"Enter PRN number for student "<<i+1<<":\t";
|
{
|
||||||
cin>>head->roll;
|
student *p;
|
||||||
cout<<"Enter name for student "<<i+1<<":\t";
|
for(p = head; p->next!= NULL; p = p->next)
|
||||||
cin>>head->name;
|
{
|
||||||
head->next=NULL;
|
cout<<p->roll<<" "<<p->name<<"->";
|
||||||
point=head;
|
}
|
||||||
|
cout<<p->roll<<" "<<p->name<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
student* student::beg_add(student *head)
|
||||||
|
{
|
||||||
|
student *p;
|
||||||
|
p = new student;
|
||||||
|
cout<<"\nEnter prn of new president: ";
|
||||||
|
cin>>p->roll;
|
||||||
|
cout<<"Enter name of new president: ";
|
||||||
|
cin>>p->name;
|
||||||
|
p->next = NULL;
|
||||||
|
p->next = head;
|
||||||
|
head = p;
|
||||||
|
return head;
|
||||||
|
}
|
||||||
|
|
||||||
|
student* student::end_add(student *head)
|
||||||
|
{
|
||||||
|
student *p,*q;
|
||||||
|
p = new student;
|
||||||
|
cout<<"\nEnter prn of secretary: ";
|
||||||
|
cin>>p->roll;
|
||||||
|
cout<<"Enter name of secretary: ";
|
||||||
|
cin>>p->name;
|
||||||
|
p->next = NULL;
|
||||||
|
for(q = head; q->next!=NULL; q = q->next);
|
||||||
|
q->next = p;
|
||||||
|
return head;
|
||||||
|
}
|
||||||
|
|
||||||
|
student* student::btwn_add(student *head)
|
||||||
|
{
|
||||||
|
int y;
|
||||||
|
student *p,*q;
|
||||||
|
p = new student;
|
||||||
|
cout<<"\nEnter prn of new member: ";
|
||||||
|
cin>>p->roll;
|
||||||
|
cout<<"Enter name of new member: ";
|
||||||
|
cin>>p->name;
|
||||||
|
cout<<"Enter prn after which new member is to be added: ";
|
||||||
|
cin>>y;
|
||||||
|
p->next = NULL;
|
||||||
|
q = head;
|
||||||
|
while(q!=NULL)
|
||||||
|
{
|
||||||
|
if(q == NULL)
|
||||||
|
{
|
||||||
|
cout<<"\nInvalid Data....."<<endl;
|
||||||
|
}
|
||||||
|
else if(q->roll == y)
|
||||||
|
{
|
||||||
|
p->next = q->next;
|
||||||
|
q->next = p;
|
||||||
|
}
|
||||||
|
q = q->next;
|
||||||
}
|
}
|
||||||
else {
|
return head;
|
||||||
point->next=new node;
|
}
|
||||||
point=point->next;
|
|
||||||
cout << "Enter PRN number for student "<<i+1<<":\t";
|
student* student::beg_del(student *head)
|
||||||
cin>>point->roll;
|
{
|
||||||
cout << "Enter name for student "<<i+1<<":\t";
|
student *p;
|
||||||
cin>>point->name;
|
p = head;
|
||||||
point->next=NULL;
|
head = head->next;
|
||||||
|
delete p;
|
||||||
|
return head;
|
||||||
|
}
|
||||||
|
|
||||||
|
student* student::end_del(student *head)
|
||||||
|
{
|
||||||
|
student *p,*q;
|
||||||
|
for(q = head; q->next->next!=NULL; q = q->next);
|
||||||
|
p = q->next;
|
||||||
|
delete p;
|
||||||
|
q->next = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
student* student::btwn_del(student *head)
|
||||||
|
{
|
||||||
|
int y;
|
||||||
|
student *p,*q;
|
||||||
|
cout<<"\nEnter prn of member which is to be deleted: ";
|
||||||
|
cin>>y;
|
||||||
|
if(head == NULL)
|
||||||
|
{
|
||||||
|
cout<<"\nLinked list is empty!!";
|
||||||
|
return head;
|
||||||
}
|
}
|
||||||
}
|
p = head;
|
||||||
return head;
|
while(p->next!=NULL)
|
||||||
|
{
|
||||||
|
if(p->next->roll==y)
|
||||||
|
{
|
||||||
|
q = p->next;
|
||||||
|
p->next = p->next->next;
|
||||||
|
delete q;
|
||||||
|
}
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
return head;
|
||||||
}
|
}
|
||||||
|
|
||||||
void node::display(node* head) {
|
student* student::total(student *head)
|
||||||
node* point=this;
|
{
|
||||||
cout<<endl<<"PRNs and names are:"<<endl;
|
student *p;
|
||||||
for (point=head; point!=NULL; point=point->next) {
|
int total = 0;
|
||||||
cout<<point->roll<<" -> "<<point->name<<endl;
|
for(p = head; p!=NULL; p = p->next)
|
||||||
}
|
{
|
||||||
cout<<endl<<"## DESIGNED AND ENGINEERED BY KSHITIJ\n## END OF CODE"<<endl;
|
total++;
|
||||||
|
}
|
||||||
|
cout<<"\nTotal Number of students are: "<<total<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
student* student::con(student *head,student *head1)
|
||||||
node* head = node::create();
|
{
|
||||||
head->display(head);
|
student *p;
|
||||||
return 0;
|
for(p = head; p->next!=NULL; p = p->next);
|
||||||
|
p->next = head1;
|
||||||
|
return head;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int flag = 1;
|
||||||
|
int flag1 = 1;
|
||||||
|
int flag2 = 1;
|
||||||
|
int char0,char1,char2;
|
||||||
|
student *head,*head1;
|
||||||
|
student obj;
|
||||||
|
while(flag)
|
||||||
|
{
|
||||||
|
cout<<"\nYOUR CHOICES ARE: ";
|
||||||
|
cout<<"\n1. LINKED LIST1: \n2. LINKED LIST2: \n3. CONCATENATE LINKED LIST 1 & 2: \n4. EXIT";
|
||||||
|
cout<<"\nEnter choice: ";
|
||||||
|
cin>>char0;
|
||||||
|
switch(char0)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
while(flag1)
|
||||||
|
{
|
||||||
|
cout<<"\nWhat operations on list1 would you like to perform?";
|
||||||
|
cout<<"\n1. Enter prn, name of members: \n2. Add new president: \n3. Add secretary: \n4. Add new members: \n5. Remove president: \n6. Remove secretary: \n7. Remove members: \n8. Total members present: \n9. Exit ";
|
||||||
|
cout<<"\nEnter choice: ";
|
||||||
|
cin>>char1;
|
||||||
|
switch(char1)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
head = obj.create();
|
||||||
|
obj.display(head);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
head = obj.beg_add(head);
|
||||||
|
obj.display(head);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
head = obj.end_add(head);
|
||||||
|
obj.display(head);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
head = obj.btwn_add(head);
|
||||||
|
obj.display(head);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
cout<<"\nRemoved president: ";
|
||||||
|
head = obj.beg_del(head);
|
||||||
|
obj.display(head);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 6:
|
||||||
|
cout<<"\nRemoved secretary: ";
|
||||||
|
obj.end_del(head);
|
||||||
|
obj.display(head);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 7:
|
||||||
|
head = obj.btwn_del(head);
|
||||||
|
cout<<"\nMember removed: ";
|
||||||
|
obj.display(head);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 8:
|
||||||
|
obj.total(head);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 9:
|
||||||
|
flag1 = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
cout<<"\nEnter valid choice!!!";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
while(flag2)
|
||||||
|
{
|
||||||
|
cout<<"\nWhat operations on list1 would you like to perform?";
|
||||||
|
cout<<"\n1. Enter prn, name of members: \n2. Add new president: \n3. Add secretary: \n4. Add new members: \n5. Remove president: \n6. Remove secretary: \n7. Remove members: \n8. Total members present: \n9. Exit ";
|
||||||
|
cout<<"\nEnter choice: ";
|
||||||
|
cin>>char2;
|
||||||
|
switch(char2)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
head1 = obj.create();
|
||||||
|
obj.display(head1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
head1 = obj.beg_add(head1);
|
||||||
|
obj.display(head1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
head1 = obj.end_add(head1);
|
||||||
|
obj.display(head1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
head1 = obj.btwn_add(head1);
|
||||||
|
obj.display(head1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
cout<<"\nRemoved president: ";
|
||||||
|
head1 = obj.beg_del(head1);
|
||||||
|
obj.display(head1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 6:
|
||||||
|
cout<<"\nRemoved secretary: ";
|
||||||
|
obj.end_del(head1);
|
||||||
|
obj.display(head1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 7:
|
||||||
|
head1 = obj.btwn_del(head1);
|
||||||
|
cout<<"\nMember removed: ";
|
||||||
|
obj.display(head1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 8:
|
||||||
|
obj.total(head1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 9:
|
||||||
|
flag2 = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
cout<<"\nEnter valid choice!!!";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
head = obj.con(head,head1);
|
||||||
|
obj.display(head);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
flag = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
cout<<"\nEnter valid choice: ";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user