Question

#C++, Programming: Program Design Including Data Structures, 7th Edition, it is too long so i can't...

#C++, Programming: Program Design Including Data Structures, 7th Edition, it is too long so i can't add the these two file.(unorderedlinked.h and linkedlist.h) as well as the output

  1. Please use the file names listed below since your file will have the following components:
  2. Ch16_Ex5_MainProgram.cpp - given file


    //22 34 56 4 19 2 89 90 0 14 32 88 125 56 11 43 55 -999

    #include
    #include "unorderedLinkedList.h"

    using namespace std;

    int main()
    {
    unorderedLinkedList list, subList;

    int num;                                                                                                                       

                cout << "Enter numbers ending with -999" << endl;                                                                                                                     
    cin >> num;                                                                                                     

                while (num != -999)                                                                                          
    {
    list.insertLast(num);                                                                  
    cin >> num;                                                                                                     
    }

                cout << endl;                                                                                                   

                cout << "List: ";                                                
    list.print();                                                                                                        
    cout << endl;                                                                                                               
    cout << "Length of the list: " << list.length() << endl;                                                                                                      

                list.divideMid(subList);

                cout << "Lists after splitting list" << endl;

                cout << "list: ";
    list.print();                                                                                                        
    cout << endl;                                                                                                               
    cout << "Length of the list: " << list.length() << endl;                  

                cout << "sublist: ";
    subList.print();                                                                                                  
    cout << endl;                                                                                                               
    cout << "Length of subList: " << subList.length() << endl;
    system("pause");
    return 0;                                                          
    }

    linkedList.h
    unorderedLinkedList.h

  3. Dividing a linked list into two sublists of almost equal sizes:
    1. Add the operation divideMid to the class linkedListType as follows:

      void divideMid(linkedListType &sublist);
      //This operation divides the given list into two sublists
      //of (almost) equal sizes.
      //Postcondition: first points to the first node and last
      //          points to the last node of the first
      //          sublist.
      //          sublist.first points to the first node
      //          and sublist.last points to the last node
      //          of the second sublist.
      Consider the following statements:

      unorderedLinkedList myList;
      unorderedLinkedList subList;

    2. Suppose myList points to the list with elements 34 65 27 89 12 (in this order). The statement:

      myList.divideMid(subList);

      divides myList into two sublists: myList points to the list with the elements 34 65 27, and subList points to the sublist with the elements 89 12.

      Write the definition of the function template to implement the operation divideMid. Also, write a program to test your function.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi, since you have not provided "unorderedlinkedlist.h" file i have to write code with assumption that unorderedlinkedlist.h has a class which gives implementation of unorderedLinkedList class and unorderedLinkedList class contains a headPtr member which points to the head of linkedList and each member in the linked list has a "next" pointer which points to the next node in the linked list

Based on above assumption here is the implementation of divideMid(linkedListType &sublist); method

void divide(linkedListType &subList)
{
//please change the below line based on your class structure
//logic of program will remain the same
Node *temp = this.headPtr;
int len=0;//finding the length of the linkedListType
while(temp!=NULL)
{
len++; //incrementing for length
temp=temp->next;
}
//ceil function is present in cmath library
// using it to find if length is odd number
int mid = ceil((float)len/2);
temp=this.headPtr;
int i=1; //counter till the mid node
//itearting the list till we find the middle node
while(temp!=NULL && i<mid )
{
i++;
temp=temp->next;
}
//setting mid to be the head of new linked list
subList.head=temp;
//setting the mid to be the end of first linked list
temp->next=NULL;
  
  
}

Add a comment
Know the answer?
Add Answer to:
#C++, Programming: Program Design Including Data Structures, 7th Edition, it is too long so i can't...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have a problem with merging the two linked lists together. In the function AscendMerge, I...

    I have a problem with merging the two linked lists together. In the function AscendMerge, I am trying to compare the values of each node in the two lists and output them into one list in ascended order. Everything works except for the one function. Can someone tell me what im doing wrong, when I run it it skips over values. #include <iostream> #include <cassert> using namespace std; struct nodeType {    int info;    nodeType *link;    nodeType *current;...

  • a7q3.cc File #include <iostream> #include <cstring> #include "ArrayList.h" using namespace std; // Algorithm copy(s) // Pre:...

    a7q3.cc File #include <iostream> #include <cstring> #include "ArrayList.h" using namespace std; // Algorithm copy(s) // Pre: s :: refToChar // Post: memory allocated on heap to store a copy // Return: reference to new string char *copy(char *s) { char *temp = new char[strlen(s)+1]; strcpy(temp,s); return temp; } void test_ListOperations(){    cout << "testing createList" << endl;    List *myList = createList(10);    if (myList == NULL){ cout << "createList failed" << endl; return; } else{ cout << "createList succeeded"...

  • CSCI 2010 Lab11 Link-Lists Lab 11A Linked-Lists Preparation Create a Visual Studio C++ Project C...

    CSCI 2010 Lab11 Link-Lists Lab 11A Linked-Lists Preparation Create a Visual Studio C++ Project C2010Lab11A Add the following to the project. //LinkedList.cpp #include <cstdlib> #include "LinkedList.h" using namespace std; //--------------------------------------------------- //List Element Members //--------------------------------------------------- ListElement::ListElement(int d, ListElement * n) {    datum=d;    next=n; } int ListElement::getDatum () const {    return datum; } ListElement const* ListElement::getNext () const {    return next; } //--------------------------------------------------- //LinkedList Members //--------------------------------------------------- LinkedList::LinkedList () {    head=NULL; } void LinkedList::insertItem(int item) {    ListElement *currPtr = head;    ListElement *prevPtr =...

  • Hello, I have some errors in my C++ code when I try to debug it. I...

    Hello, I have some errors in my C++ code when I try to debug it. I tried to follow the requirements stated below: Code: // Linked.h #ifndef INTLINKEDQUEUE #define INTLINKEDQUEUE #include <iostream> usingnamespace std; class IntLinkedQueue { private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position Node *pp ; // previous position int size; // number of elements in the queue public: IntLinkedQueue();...

  • C++ Modify this program (or create your own) so that it performs the following tasks: 1....

    C++ Modify this program (or create your own) so that it performs the following tasks: 1. Insert the numbers into the list in sorted order (ascending). This will require you to keep the list sorted as you continue to insert new numbers. 2. When adding a new number, first check to see whether it is larger than the last number currently in the list. If it is, add it directly to the end of the list, i.e., do not traverse...

  • Objectives Familiarize the student with: implementing data structures in C++; dynamic allocation of C++ objects. Scenario...

    Objectives Familiarize the student with: implementing data structures in C++; dynamic allocation of C++ objects. Scenario There are some classic data structures in computer science. One example of this that you've seen in the lectures is called the stack. In the next few exercises, we'll build yet another classic data structure, the linked list. To be exact, we'll be building the singly linked list. The building block of a singly linked list is a node, which consists of two parts:...

  • Please program in C++ and document the code as you go so I can understand what...

    Please program in C++ and document the code as you go so I can understand what you did for example ///This code does~ Your help is super appreciated. Ill make sure to like and review to however the best answer needs. Overview You will revisit the program that you wrote for Assignment 2 and add functionality that you developed in Assignment 3. Some additional functionality will be added to better the reporting of the students’ scores. There will be 11...

  • The source code I have is what I'm trying to fix for the assignment at the...

    The source code I have is what I'm trying to fix for the assignment at the bottom. Source code: //Group 1 - Jodie Butterworth, Brandon Kidd, Matt Heckler //11-21-19 //CSC 201 // Exercise to practice the basic manipulations of a linked list // Note: Uses nullptr, so need to make sure your compiler is set to use C++11 // In Code::Blocks this is under Settings==>Compiler #include <iostream> using namespace std; // Structure to contain data for a node (Could be...

  • please help!!!! JAVA I done the project expect one part but I still give you all...

    please help!!!! JAVA I done the project expect one part but I still give you all the detail that you needed... and I will post my code please help me fix the CreateGrid() part in main and make GUI works    List Type Data Structures Overview : You will be implementing my version of a linked list. This is a linked list which has possible sublists descending from each node. These sublists are used to group together all nodes which...

  • WONT COMPILE ERROR STRAY / TEXT.H AND CPP PROGRAM SAYING NOT DECLARED HAVE A DRIVER WILL...

    WONT COMPILE ERROR STRAY / TEXT.H AND CPP PROGRAM SAYING NOT DECLARED HAVE A DRIVER WILL PASTE AT BOTTOM MOVIES.CPP #include "movies.h" #include "Movie.h" Movies *Movies::createMovies(int max) { //dynamically create a new Movies structure Movies *myMovies = new Movies; myMovies->maxMovies = max; myMovies->numMovies = 0; //dynamically create the array that will hold the movies myMovies->moviesArray = new Movie *[max]; return myMovies; } void Movies::resizeMovieArray() { int max = maxMovies * 2; //increase size by 2 //make an array that is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT