Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- struct Node {
- public:
- int roll;
- Node *next;
- Node () {
- next = nullptr;
- }
- Node (int roll) {
- this->roll = roll;
- next = nullptr;
- }
- };
- class Set {
- Node *hU, *hV, *hB;
- int *UniSet, *Vanilla, *Butterscotch;
- int nU, nV, nB;
- int *r1, *r2, *r3;
- int n1, n2, n3;
- int *arr;
- public:
- Set () {
- hU = hV = hB = nullptr;
- UniSet = Vanilla = Butterscotch = nullptr;
- }
- int *fillSet(int cardinality) {
- arr = new int[cardinality];
- for (int i = 0; i < cardinality; i++) {
- cout << "Enter Roll No.: ";
- cin >> arr[i];
- }
- return arr;
- }
- void genU() {
- cout << "\nUniversal Set" << endl;
- cout << "Enter the total number of Students: "; cin >> nU;
- //UniSet = new int[nU];
- UniSet = fillSet(nU);
- hU = createLL(UniSet, nU);
- }
- void genVanilla() {
- cout << "\nVanilla Set" << endl;
- cout << "Enter the number of Students who like Vanilla: "; cin >> nV;
- //Vanilla = new int[nV];
- Vanilla = fillSet(nV);
- hV = createLL(Vanilla, nV);
- }
- void genButterscotch() {
- cout << "\nButterscotch Set" << endl;
- cout << "Enter the number of Students who like Butterscotch: "; cin >> nB;
- //Butterscotch = new int[nB];
- Butterscotch = fillSet(nB);
- hB = createLL(Butterscotch, nB);
- }
- Node *createLL(int *set, int size) {
- if (size == 0) return nullptr;
- Node *head = new Node(set[0]);
- Node *temp = head;
- for (int i = 1; i < size; i++) {
- temp->next = new Node(set[i]);
- temp = current->next;
- }
- return head;
- }
- void display() {
- int choice;
- Node *head = nullptr;
- cout << "1. Universal Set\n2. Vanilla\n3. Butterscotch\n";
- cout << "Enter choice: ";
- if (choice == 1) head = hU;
- else if (choice == 2) head = hV;
- else if (choice == 3) head = hB;
- else cout << "Invalid Choice" << endl;
- Node *temp = head;
- while (temp != nullptr) {
- cout << temp->roll << " " << endl;
- temp = temp->next;
- }
- cout << endl;
- // No longer needed cuz LL
- // for (int i = 0; i < num; i++) cout << arr[i] << " ";
- }
- // Students who like both vanilla and butterscottch
- void op1() {
- Node *tempV = hV;
- Node *intersectHead = nullptr;
- Node *intersectTail = nullptr;
- while (tempV != nullptr) {
- Node *tempB = hB;
- (while tempB != nullptr) {
- if (tempV->roll == tempB->roll) {
- Node *newNode = new Node(tempV->roll);
- if(intersectHead == nullptr) intersectHead = intersectTail = newNode;
- else {
- intersectTail->next = newNode;
- intersectTail = newNode;
- }
- break;
- }
- tempB = tempB->next;
- }
- tempA = tempA->next;
- }
- }
- // Stundets who like vanilla or butterscotch or not both
- void op2() {
- }
- // Number of students who like neither vanilla nor butterscotch
- void op3() {
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment