Untitled
unknown
plain_text
15 days ago
3.8 kB
3
Indexable
Never
#include <iostream> #include <string.h> using namespace std; class student { public: int prn; string name; float cgpa; student *next; student() { next = NULL; } }; class studentlist { student *head; public: studentlist() { head = NULL; } void create(); void display(); }; void studentlist ::create() { student *temp, *p; char ch; do { temp = new student(); cout << "Enter PRN, Name and CGPA : "; cin >> temp->prn >> temp->name >> temp->cgpa; if (head == NULL) head = temp; else { p = head; while (p->next != NULL) p = p->next; p->next = temp; } cout << "\n Do you want to add more"; cin >> ch; } while (ch != 'n'); } void studentlist ::display() { student *p; p = head; cout << "\nStudent Details : \n"; cout << "PRN " << "\tName " << "\tCGPA " << "\t" << endl; while (p != NULL) { cout << p->prn << "\t" << p->name << "\t " << p->cgpa << "\t" << endl; p = p->next; } } int main() { studentlist s; s.create(); s.display(); return 0; } #include<iostream> using namespace std; class node { public: string name; char gender; int seat_no; node *next; node() { next=NULL; } }; class sll { public: node *head; int count; sll() { head=NULL; count = 0; } void create(); void display(); void insert(); void del(int x); void serach(int x); void update(int x); void sort(); }; void sll::create() { node *temp,*p; char ch; do { count++; temp=new node; cout<<"\n Enter name : "; cin>>temp->name; cout<<"\n Enter gender:"; cin>>temp->gender; cout<<"\n Enter seat no:"; cin>>temp->seat_no; temp->next=NULL; if(head==NULL) { head=temp; } else { node *p; p=head; while(p->next!=NULL) { p=p->next; } p->next=temp; } cout<<"Do you want to continue(y/n)"<<endl; cin>>ch; }while(ch=='y'); } void sll::display() { node *p; p=head; while(p!=NULL) { cout<<"Name:"<<p->name<<endl; cout<<"Gender:"<<p->gender<<endl; cout<<"Seat no:"<<p->seat_no<<endl; p=p->next; } } void sll::insert() { node *temp,*p; temp=new node; cout<<"Enter name"<<endl; cin>>temp->name; cout<<"Enter gender"<<endl; cin>>temp->gender; cout<<"Enter seat no"<<endl; cin>>temp->seat_no; int loc; cout<<"Enter the location of new node:"<<endl; cin>>loc; if(loc==1) { temp->next=head; head=temp; count++; } else if(loc>=count) { node *p =head; while(p->next!=NULL) { p=p->next; } p->next=temp; count++; } else { node *p=head; for(int i=1; i<count; i++) { p=p->next; } temp->next = p->next; p->next =temp; count++; } } int main() { sll s; int choice; char n; do { cout<<"1. Create \n2. Display \n3.Insert \n4.Delete \n"; cout<<"Enter your choice: "<<endl; cin>>choice; switch(choice) { case 1: { s.create(); break; } case 2: { s.display(); break; } case 3: { s.insert(); s.display(); break; } } cout<<"Do you want to continue:"; cin>>n; }while(n=='y'); return 0; } void sll::del(int x) { node *curr,*prev; curr=head; prev=NULL; int info; cout<<"Info of the node to be deleted"<<endl; cin>>info; curr=head; prev=NULL; while(curr!=NULL) { if(curr->seat_no==info) { if(curr=head) { } } } }
Leave a Comment