0% found this document useful (0 votes)
6 views

DSL CODE 7

Uploaded by

fuoco414
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

DSL CODE 7

Uploaded by

fuoco414
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

DSL CODE 7

INPUTE:-

#include <iostream>

#include <cstring>

using namespace std;

struct node {

int prn, rollno;

char name[50];

node* next;

};

class Info {

node *head = NULL;

public:

node* create();

void insertPresident();

void insertMember();

void insertSecretary();

void deletePresident();

void deleteMember();

void deleteSecretary();

void display();

void countMembers();

void reverseList();

void reverseDisplay(node* temp);

void concatenate();
};

node* Info::create() {

node *p = new node;

char a[50];

cout << "Enter name of student: ";

cin >> a;

strcpy(p->name, a);

cout << "Enter PRN of student: ";

cin >> p->prn;

cout << "Enter roll number of student: ";

cin >> p->rollno;

p->next = NULL;

return p;

void Info::insertPresident() {

node *p = create();

if (head == NULL) {

head = p;

} else {

p->next = head;

head = p;
}

void Info::insertMember() {

node *p = create();

if (head == NULL) {

head = p;

} else {

node *temp = head;

while (temp->next != NULL) {

temp = temp->next;

temp->next = p;

void Info::insertSecretary() {

node *p = create();

if (head == NULL) {

head = p;

} else {

node *temp = head;

while (temp->next != NULL) {

temp = temp->next;

}
temp->next = p;

void Info::deletePresident() {

if (head == NULL) {

cout << "List is empty, cannot delete president." << endl;

return;

node *temp = head;

head = head->next;

delete temp;

void Info::deleteMember() {

if (head == NULL) {

cout << "List is empty, cannot delete member." << endl;

return;

int prnToDelete;

cout << "Enter PRN of member to delete: ";

cin >> prnToDelete;

node *temp = head;

node *prev = NULL;


while (temp != NULL && temp->prn != prnToDelete) {

prev = temp;

temp = temp->next;

if (temp == NULL) {

cout << "Member not found!" << endl;

return;

if (prev != NULL) {

prev->next = temp->next;

} else {

head = temp->next;

delete temp;

cout << "Member deleted." << endl;

void Info::deleteSecretary() {

if (head == NULL) {

cout << "List is empty, cannot delete secretary." << endl;

return;

}
node *temp = head;

node *prev = NULL;

while (temp->next != NULL) {

prev = temp;

temp = temp->next;

if (prev != NULL) {

prev->next = NULL;

} else {

head = NULL;

delete temp;

void Info::display() {

if (head == NULL) {

cout << "List is empty." << endl;

return;

node *temp = head;


cout << "PRN\tRoll No\tName" << endl;

while (temp != NULL) {

cout << temp->prn << "\t" << temp->rollno << "\t" << temp->name << endl;

temp = temp->next;

void Info::countMembers() {

int count = 0;

node *temp = head;

while (temp != NULL) {

count++;

temp = temp->next;

cout << "Count of members: " << count << endl;

void Info::reverseList() {

reverseDisplay(head);

void Info::reverseDisplay(node *temp) {

if (temp == NULL) {

return;

}
reverseDisplay(temp->next);

cout << temp->prn << "\t" << temp->rollno << "\t" << temp->name << endl;

void Info::concatenate() {

Info list2;

int n;

cout << "Enter the number of members in the second list: ";

cin >> n;

for (int i = 0; i < n; i++) {

list2.insertMember();

node *temp = head;

if (temp == NULL) {

head = list2.head;

} else {

while (temp->next != NULL) {

temp = temp->next;

temp->next = list2.head;

cout << "Concatenated list:" << endl;


display();

int main() {

Info info;

int choice;

char ch;

do {

cout << "\nMenu:\n";

cout << "1. Insert President\n";

cout << "2. Insert Member\n";

cout << "3. Insert Secretary\n";

cout << "4. Delete President\n";

cout << "5. Delete Member\n";

cout << "6. Delete Secretary\n";

cout << "7. Display Members\n";

cout << "8. Count Members\n";

cout << "9. Display Reverse\n";

cout << "10. Concatenate Two Lists\n";

cout << "Enter your choice: ";

cin >> choice;

switch (choice) {

case 1:
info.insertPresident();

break;

case 2:

info.insertMember();

break;

case 3:

info.insertSecretary();

break;

case 4:

info.deletePresident();

break;

case 5:

info.deleteMember();

break;

case 6:

info.deleteSecretary();

break;

case 7:

info.display();

break;

case 8:

info.countMembers();

break;

case 9:

info.reverseList();
break;

case 10:

info.concatenate();

break;

default:

cout << "Invalid choice!" << endl;

cout << "Do you want to continue? (y/n): ";

cin >> ch;

} while (ch == 'y' || ch == 'Y');

return 0;

You might also like