[Solved] CS2040C Assignment 2-Template and Linked List Sorting

$25

File Name: CS2040C_Assignment_2-Template_and_Linked_List_Sorting.zip
File Size: 499.26 KB

SKU: [Solved] CS2040C Assignment 2-Template and Linked List Sorting Category: Tag:
5/5 - (1 vote)

A zip file of the solution files for MS Visual Studio (or .zip of XCode file for Mac users) is provided that contains

  • The Linked List class mentioned in lecture

o simpleLinkedListTemplate.h o simpleLinkedListTemplate.hpp (or .cpp, it doesnt matter)

  • A main file to use the Linked List: cpp
  • And the files for class Food: h, food.cpp

You will only submit the modifications in these two files ONLY:

  • h
  • cpp

More precisely, you will only submit the following to coursemology only:

  • The List class declaration (optional, only if you had modified it)
  • exist()
  • extractMax() reverseOp()
  • And any new auxiliary functions you have added.

However, you can modify other files, especially for your own testing and debugging. But in our grading, we will assume all the other files are the not changed.

More precisely, you are only allowed to ADD more helping members or methods and you should NOT change the existing implemented declarations and implementations

Look into the main.cpp file. It contains the code:

int main() { testIntLL(); testFoodExist(); testFoodOpGreaterThan(); testFoodAddition(); testFoodSort(); testReverseOp(); return 0;

}

Task 1

The member function exist() is missing. Your job is to implement it in the same way you did in the previous assignment. Here is some sample output:

Task 2

Task 2 is to implement the operation + for food. For example:

Food food1(Salad, 100);

Food food2(Chicken, 200);

Food food3(Curry, 40);

Food food23 = food2 + food3;

So the name of food23 will be Chicken Curry with 240 calories. Here is the sample output for the code given:

Task 3

To implement the function extractMax() in List<T>. This function will

  • Find the maximum item in the list
  • delete the node in the list and return the maximum item

Sample output:

If you have done it right, you can use it to sort the list by:

while (!l.empty())

cout << l.extractMax() << ;

cout << endl

And it should work for any class like Food also, if you implement it correctly:

Task 4

Write down your thoughts. What are the disadvantages of the LinkedList extractMax Sorting? List at least two disadvantages in coursemology.

Task 5

Implement the function reverseOp() in the class List. It will reverse the order of the items in the list. Each time you call l.reverseOp() to modify itself. Sample output from the function testReverseOp():

Extra Tasks (Not Graded)

If you are looking for extra challenges, you could try the followings by yourself.

  • Implement the == operators for the class Food
  • Google how did we do cout << food;
  • Implement another class to use it with the LinkedList Look at the slides for an example of a class called Hero.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CS2040C Assignment 2-Template and Linked List Sorting
$25