CS301 Assignment 1 Solution and Discussion


  • Cyberian's Gold

    Assignment No. 01
    Semester Fall 2019
    CS301- Data Structures Total Marks: 20

    Due Date : 18-Nov-2019
    Instructions
    Please read the following instructions carefully before solving & submitting assignment:
    It should be clear that your assignment will not get any credit (zero marks) if:
    o The assignment is submitted after due date.
    o The submitted code does NOT compile.
    o The submitted assignment is other than .CPP file.
    o The submitted assignment does NOT open or file is corrupted.
    o The assignment is copied (from other student or ditto copy from handouts or internet).
    Uploading instructions
    For clarity and simplicity, You are required to Upload/Submit only ONE .CPP file.

    Note: Use ONLY Dev-C++ IDE.
    Objective
    The objective of this assignment is

    o To make you familiar with implementing the Doubly Linked List data structure in C++ programming language.

    For any query about the assignment, contact at [email protected]

    GOOD LUCK

    Marks: 20
    Problem Statement:

    You have to implement a Double Linked List in C++ language in which you have to create a structure and two classes as given below:

    1. A structure named as “StudentDetail” by using struct keyword.
      StudentDetail structure should consist of following data members of type “string”.
      name
      vuid

    2. A node class named as “Node” by using class keyword.
      Node class will have following data members and member functions:
      cda47932-36ec-4210-ab0a-b3bee8bce8dc-image.png

       (“X” denotes StudentDetail variable means the student details and “Y” denotes the data value of the node).
      
    3. A doubly linked list class named as “DoublyLinkedList” by using class keyword.
      DoublyLinkedList class will have following data members and member functions:
      a46ffa50-421f-4ab2-9d20-67bfac975435-image.png

    Detailed description of member functions of DoublyLinkList class:

    1. addAtBegining(X): To add the node at the beginning of the doubly linked list class.
      4da1ea58-b161-48f7-98b0-9684d220156b-image.png

    2. addAtEnd(X): To add the node at the End of the doubly linked list class.
      08b97a59-7a5e-4312-9d83-5cdb81890a8f-image.png

    3. delNode(): To delete a node pointed by current pointer in the doubly linked list.
      59d9f4dd-919a-4db9-991a-950c4d6bb829-image.png

    4. display():To display all student details in doubly linked list.

            (“X” denote Node to add in the doubly linked list).
      

    In the main ( ) function you have to do the following:

    1. Create two objects of type StudentDetail at the Beginning of the doubly linked list class using addATBegining (X) method of DoublyLinkedList and use display() method to display doubly linked list.
      Note that first object should contain your own VU ID and your own name otherwise you will get zero marks.

    2. Create one objects of type StudentDetail at the End of the doubly linked list class using addAtEnd (X) method of DoublyLinkedList and use display() method to display doubly linked list.

    3. Delete current node of the doubly linked list and use display() method to display doubly linked list.

    4. Display doubly linked list after calling each functions.

    Detailed Output Screenshot:
    fcd2ba41-d1ae-4c73-9648-8180c609cba1-image.png

    Lectures Covered: This assignment covers Lecture # 1-8.
    Deadline: Your assignment must be uploaded/submitted at or before 18-Nov-2019.


  • Cyberian's Gold

    .CPP File Code

    using namespace std;
     
    #include <stdlib.h>
    #include <iostream>
     
    struct StudentDetail{
         
        string name;
        string vuid;
         
         
    };
     
    //class Node* head;
     
     
    class Node{
         
        struct StudentDetail newStd;
        class Node* next;
        class Node* prev;
         
        void Set(string name,string vuid)
        {
            newStd.name=name;
            newStd.vuid=vuid;
             
             
        }
         
        Node Get()
        {
                 
        }
         
        void setNext(string name,string vuid){
             
            if(next==NULL)
            {
                 
            }
            else
            {
                class Node* newNode= new Node();
                 
                    newStd.name=name;
                    newStd.vuid=vuid;
                    newNode->next= newNode;
             
                 
                 
        }   }
         
        string getNext()
        {
            next;
             
        }
         
            void setPrev(string name,string vuid){
             
            if(next==NULL)
            {
                 
            }
            else
            {
                class Node* newNode= new Node();
                 
                    newStd.name=name;
                    newStd.vuid=vuid;
                    newNode->next= newNode;
             
                 
                 
        }   }
         
            string getPrev()
        {
            prev;
             
        }
         
         
    };
     
     
     
    class DoublyLinkedList{
        public:
        struct StudentDetail newStd;
    class DoublyLinkedList* headPtr;
    class DoublyLinkedList* curPtr;
    class DoublyLinkedList* nextPtr;
    int size;
    //dfdf
     
    class DoublyLinkedList* headDlinkList=NULL;
     
    void addAtBegining(string vuid, string name)
    {
    class DoublyLinkedList* dNode= new DoublyLinkedList();
     
        dNode->newStd.vuid=vuid;
        dNode->newStd.name=name;
        dNode->nextPtr=headDlinkList;
        headDlinkList= dNode;
        dNode->curPtr=dNode;
         
         
         
        }
         
    void addAtEnd(string vuid, string name)
    {
     
        class DoublyLinkedList* dNode= new DoublyLinkedList();
     
        dNode->newStd.vuid=vuid;
        dNode->newStd.name=name;
        dNode->nextPtr=headDlinkList;
        headDlinkList= dNode;
            dNode->curPtr=dNode;
         
        }   
         
         
     void delNode()
     {
        class DoublyLinkedList* temp1=curPtr;
        class DoublyLinkedList* temp2= temp1;
        temp1->nextPtr= temp2->nextPtr;
         
        free(temp2);
         
         
         
         
         
     }
         
         
         
         
        void print()
        {
         
       class DoublyLinkedList* temp= headDlinkList;
        
       while(temp!=NULL)
       {
     cout<<temp->newStd.vuid<<"      "<<temp->newStd.name<<endl;  
        temp= temp->nextPtr;
             
    }
             
        }
     
     
     
     
         
    };
     
     
     
     
    int main()
    {
        string vuid,name;
         
    cout<<"Add your vuID and Name at First Position "<<endl;
    cout<<"_ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _"<<endl;
     
        DoublyLinkedList dlist1;
     
         
        cin>>vuid;
        cin>>name;
         
        dlist1.addAtBegining(vuid,name);
        dlist1.print();
         
        cout<<"Insertion At Beginning in doubly Link List "<<endl;
        cout<<"_ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _"<<endl;
            cin>>vuid;
        cin>>name;
        dlist1.addAtBegining(vuid,name);
    dlist1.print(); 
     
            cout<<"Insertion At End in doubly Link List "<<endl;
        cout<<"_ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _"<<endl;
        cin>>vuid;
        cin>>name;
            dlist1.addAtEnd(vuid,name);
    dlist1.print(); 
            cout<<"Deletion of Current Node (Last Node) "<<endl;
        cout<<"_ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ __ _ _"<<endl;
        dlist1.delNode();
        dlist1.print();
         
    }
    

    Download .cpp File


  • Cyberian's Gold



    Recent Topics


|