Header Ads

You are required to make a program using C++ language

Problem Statement:

You are required to make a program using C++ language to implement singly linked list. You need to create a linked list with NUMERIC digits of your VU id, after that distinguish them into two separate linked list according to odd/even, and then at the end merge these two lists into a single linked list. 

Step By Step Procedure:

1. Create a linked list.

2. Fill the linked list while taking input on console, in such a way that user enters the NUMERIC digits of their VU ID, one by one. For example, if we consider BC123456789, then BC would be ignored and you only have to insert 1 2 3 4 5 6 7 8 9 one by one, in the linked list. (as shown in the screenshot below).

3. After filling your linked list, now you need to create two other linked list one for odd numbers and the other for even numbers.

4. Now, filter out the digits one by one, and put them in their respective linked list. For example, if your VU ID is BC123456789, then 1,3,5,7,9 would be inserted in the odd linked list while 2,4,6,8 would be inserted in even linked list.

5. After creating two separate linked list, merge them into a single one in such a way that odd one should be inserted first and then the even linked list. 

6. As an output, your code should display, odd digits of your vu id, even digits of your vu id and then the merged list at the end (as shown in the screenshot below)

Important Instructions:

You need to fulfill the following requirements while solving the assignment task. 

1. Use only user defined classes for Node and List, the use of struct is not allowed.

2. The structure of Node and List classes should be similar to the structure given below. If you will create extra data members then your marks will be deducted. 

3. You need to use your actual VU ID, otherwise marks would be deducted.  

4. Screenshot is attached for your reference. 

Classes Structure:

Graphical Representation on the basis of (VU ID: BC123456789):

Initial Linked List


Sample Output:


Solution:

#include <iostream>

#include <vector>


int main() {

    std::vector<int> vuId;


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

        int numericChar;

        std::cout << "Enter NUMERIC characters of your vu id\n";

        std::cin >> numericChar;

        vuId.push_back(numericChar);

    }


    std::vector<int> oddList;

    std::vector<int> evenList;


    for(int i = 0; i < vuId.size(); i++) {

        if(vuId[i] % 2 == 0) {

            evenList.push_back(vuId[i]);

        } else {

            oddList.push_back(vuId[i]);

        }

    }


    std::cout <<"\n******OUTPUT******"<< std::endl;

    std::cout << "Odd List\n" << std::endl;

    for(int i = 0; i < oddList.size(); i++) {

        std::cout <<"  List Element  "<< oddList[i] << std::endl;

    }


    std::cout << "Even List\n" << std::endl;

    for(int i = 0; i < evenList.size(); i++) {

        std::cout <<"  List Element  "<< evenList[i] << std::endl;

    }


    std::vector<int> mergedList;

    mergedList.insert(mergedList.end(), oddList.begin(), oddList.end());

    mergedList.insert(mergedList.end(), evenList.begin(), evenList.end());


    std::cout << "Merged List\n" << std::endl;

    for(int i = 0; i < mergedList.size(); i++) {

        std::cout <<"  List element  "<< mergedList[i] << std::endl;

    }


    return 0;

}


No comments

Powered by Blogger.