CS311 Programming Assignment 2 Total points: 10 This assignment is based on the linked list data structure from assignment 1. You must have a working LinkedList data structure. We will implement the following two functions on input linked lists: Union Linked Lists Assume two linked lists that represent Set A and Set B respectively. Implement the following function to obtain their union A U B and return the result as a new linked list. Note that a Set should not contain duplicate elements (e.g., integers), but its elements are not assumed to be sorted in the list. The definition of the function unionLinkedList is as the following:   LinkedList unionLinkedList (const LinkedList& LA, const LinkedList& LB) For example, if   LA = (3, 5, 8, 11) LB = (2, 6, 8, 9, 22, 24) Then unionLinkedList(LA, LB) = (3, 5, 8, 11, 2, 6, 9, 22, 24). Note the list isn’t sorted. To compute the union operation, you need to implement the LinkedList search function to check whether a value is in the list or not. Merge Linked Lists Assume two input linked lists, LA and LB, whose elements are both in the non-descending order (duplicates may exist). Implement the following function to merge LA and LB into a new linked list (as the return value). The elements in the new list should still be in the non-descending order. The definition of the function mergeLinkedList is as the following:   LinkedList mergeLinkedList (const LinkedList& LA, const LinkedList& LB);  For example, if LA = (3, 5, 8, 11) LB = (2, 6, 8, 9, 22, 24) Then mergeLinkedList (LA, LB) = (2, 3, 5, 6, 8, 8, 9, 11, 22, 24). Note same values may repeat Testing To build the test executable test, type make at the command line. Then run the test and confirm the outputs match what are in the "test_out.txt" file. $ make $ ./test Your code should work correctly for all tests and be robust for potential error conditions, and free of dangerous code constructs and memory leaks. We will use tools like cppcheck and valgrind to to grade your code and catch memory leaks.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 18PE
icon
Related questions
Question

CS311 Programming Assignment 2

Total points: 10

This assignment is based on the linked list data structure from assignment 1. You must have a working LinkedList data structure. We will implement the following two functions on input linked lists:

Union Linked Lists

Assume two linked lists that represent Set A and Set B respectively. Implement the following function to obtain their union A U B and return the result as a new linked list. Note that a Set should not contain duplicate elements (e.g., integers), but its elements are not assumed to be sorted in the list. The definition of the function unionLinkedList is as the following:

 

LinkedList unionLinkedList (const LinkedList& LA, const LinkedList& LB)

For example, if

 

LA = (3, 5, 8, 11) LB = (2, 6, 8, 9, 22, 24)

Then unionLinkedList(LA, LB) = (3, 5, 8, 11, 2, 6, 9, 22, 24). Note the list isn’t sorted. To compute the union operation, you need to implement the LinkedList search function to check whether a value is in the list or not.

Merge Linked Lists

Assume two input linked lists, LA and LB, whose elements are both in the non-descending order (duplicates may exist). Implement the following function to merge LA and LB into a new linked list (as the return value). The elements in the new list should still be in the non-descending order. The definition of the function mergeLinkedList is as the following:

 

LinkedList mergeLinkedList (const LinkedList& LA, const LinkedList& LB); 

For example, if

LA = (3, 5, 8, 11)

LB = (2, 6, 8, 9, 22, 24)

Then mergeLinkedList (LA, LB) = (2, 3, 5, 6, 8, 8, 9, 11, 22, 24). Note same values may repeat

Testing

To build the test executable test, type make at the command line. Then run the test and confirm the outputs match what are in the "test_out.txt" file.

$ make

$ ./test

Your code should work correctly for all tests and be robust for potential error conditions, and free of dangerous code constructs and memory leaks. We will use tools like cppcheck and valgrind to to grade your code and catch memory leaks.

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage