QuestionQuestion

You will create a new List class that holds a singly linked list of Course pointers. You will implement the linked list as we saw in class, with no dummy nodes. The List class will contain the following:
• a data member for the head of the list
• a data member for the tail of the list
• a constructor
• a destructor to clean up the dynamically allocated memory
• a member function with the prototype void add(Course*) that adds a new course to the list
◦ the new course will be added in its correct position in the list, in ascending (increasing) order by course, using the Course class’s lessThan() function
◦ you will need to implement a Node class, as we saw in class
• a print() member function that prints the courses to the screen
◦ after all data is printed, indicate which course is at the head and which course is at the tail

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <iostream>
using namespace std;
#include <string>

#include "List.h"

List::List() : head(0), tail(0) {
}

List::~List() {
    Node* currNode = head;
    Node* nextNode;

    while (currNode != 0) {
       nextNode = currNode->next;
       delete currNode->data;
       delete currNode;
       currNode = nextNode;
    }
}

void List::add(Course* course) {
   
    // bad case
    if (course == 0) {
       return;
    }

    // make new node
    Node * n = new Node;
    n->data = course;
    n->next = 0;
   
    // empty list
    if (head == 0) {
       head = n;
       tail = n;
       return;
    }

    // add to the head of list
    if (course->lessThan(head->data)) {
       n->next = head;
       head = n;
       return;
    }

    // add to the end of list
    if (tail->data->lessThan(course)) {
       tail->next = n;
       tail = n;
       return;
    }...

By purchasing this solution you'll be able to access the following files:
solution.zip.

50% discount

Hours
Minutes
Seconds
$41.00 $20.50
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats