Sponsored Links


Results 1 to 2 of 2

Thread: CS301- Data Structures Assignment No.1 Solution Spring 2014

  1. #1
    Zombee
    Guest

    CS301- Data Structures Assignment No.1 Solution Spring 2014

    Sponsored Links1





    Total Marks: 20

    Due Date:
    Wednesday, May 07, 2014

    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:
    The assignment is submitted after due date.
    The submitted code does NOT compile.
    The submitted assignment file is other than .CPP format.
    The submitted assignment file does not open or corrupted.
    The assignment is copied (from other student or copied from handouts or internet).

    Uploading instructions
    Don’t wait for grace day. Grace Day is given only if there is problem with LMS on due date. Submit your solution within due date.
    Note that no assignment will be accepted through email if there is any problem on grace day.

    Note: Use only dev-C++ IDE.

    Objective
    The objective of this assignment is

    To make you familiar with list data structures and programming techniques to implement list data structure by using linked list.

    Question:

    Sponsored Links

    I am sending you a C++ program related to linked list along with your assignment file. In the given C++ program, I did not write some functions. Name of these functions are given below.

    1) main()
    2) List add Nodes(int number)
    3) void split(int c, List list, List large List, List small List)
    4) void difference List(List list A, List list B)

    Your assignment is to write the codes of these functions so that given program could be compiled and run to perform the required functionality/purpose.
    Moreover required functionality/purpose of this C++ program is to perform the following tasks given below by using a linked list.

    Splitting up an odd list:
    1) Your program should ask the user to input any number.
    2) Create a linked list that will contain all the odd elements less than the number which you entered in first step. Also display this list.
    3) Now ask the user to enter any pivot element. Pivot element is a simple integer number. Use this pivot element to divide the list into two halves. First half will contain all the elements smaller than that pivot element. Save this first half into a list called small List. Second half will contain all the elements larger than that pivot element. Save this second half into a list called large List.
    4) Display small List and Large List that you formed in step 3.

    Performing set difference operation on two odd lists:
    1) Your program should ask the user to input any two integer number for example 30 and 20.
    2) Create a linked list i.e. ‘list A’ that will contain all the odd elements less than the number 30 which you entered in first step. Also display this list.
    3) Create a linked list i.e. ‘list B’ that will contain all the odd elements less than the number 20 which you entered in first step. Also display this list.
    4) Perform the set difference operation on the two lists ‘list A’ and ‘list B’.
    5) Save the result of set difference operation in another list called set Difference and then display the list set Difference.

    Note:

    1) Pivot element should be positive, greater than 0 and pivot element must also be from the list.




  2. #2
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578
    I am sending you a C++ program related to linked list along with your assignment file. In the given C++ program, I did not write some functions. Name of these functions are given below.

    1) main()
    2) List addNodes(int number)
    3) void split(int c, List list, List largeList, List smallList)
    4) void differenceList(List listA, List listB)
    Linked List:
    #include <iostream.h>
    #include <stdlib.h>

    class Node
    {
    public:
    int get() { return object; };
    void set(int object) { this->object = object; };
    Node * getNext() { return nextNode; };
    void setNext(Node * nextNode) { this->nextNode = nextNode; };
    private:
    int object;
    Node * nextNode;
    };


    class List
    {
    public:
    List();
    void add (int addObject);
    int get();
    bool next();
    friend void traverse(List list);
    friend List addNodes(int number);
    friend void split(int c, List list, List largeList, List smallList);
    friend void differenceList(List listA, List listB);



    private:
    int size;
    Node * headNode;
    Node * currentNode;
    Node * lastCurrentNode;
    };
    /* Constructor */
    List::List()
    {
    headNode = new Node();
    headNode->setNext(NULL);
    currentNode = NULL;
    lastCurrentNode = NULL;
    size = 0;
    }
    /* add() class method */
    void List::add (int addObject)
    {
    Node * newNode = new Node();
    newNode->set(addObject);
    if( currentNode != NULL )
    {
    newNode->setNext(currentNode->getNext());
    currentNode->setNext( newNode );
    lastCurrentNode = currentNode;
    currentNode = newNode;
    }
    else
    {
    newNode->setNext(NULL);
    headNode->setNext(newNode);
    lastCurrentNode = headNode;
    currentNode = newNode;
    }
    size ++;
    }
    /* get() class method */
    int List::get()
    {
    if (currentNode != NULL)
    return currentNode->get();
    }
    /* next() class method */
    bool List::next()
    {
    if (currentNode == NULL) return false;
    lastCurrentNode = currentNode;
    currentNode = currentNode->getNext();
    if (currentNode == NULL || size == 0)
    return false;
    else
    return true;
    }
    /* Friend function to traverse linked list */
    void traverse(List list)
    {
    Node* savedCurrentNode = list.currentNode;
    list.currentNode = list.headNode;
    cout "\n\n Elements of list are given below ";
    for(int i = 1; list.next(); i++)
    {
    cout "\n Element " i " " list.get();
    }
    cout "\n List size = " list.size '\n';
    list.currentNode = savedCurrentNode;
    }

    void split(int c, List list, List largeList, List smallList)
    {

    }



    List addNodes(int number)
    {

    }

    void differenceList(List listA, List listB){

    }



    main()
    {


    }


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 04-27-2013, 10:07 PM
  2. Replies: 0
    Last Post: 06-18-2012, 11:43 PM
  3. Replies: 19
    Last Post: 11-17-2011, 05:51 PM
  4. Replies: 7
    Last Post: 06-29-2011, 10:17 PM
  5. Replies: 9
    Last Post: 05-02-2011, 05:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft