[Solved]-Question 1 16 Points Suppose Representing Sets Integers Sorted Singly Linked Lists Sorted Q37185122


QUESTION 1 (16 points)Suppose we are representing sets of integers with sorted singly-linked lists (sorted in ascendinq order). For example, consider this set: 12, 18, 3, -5, 99, 6 We would represent it as the linked list -5, 2, 3, 6, 18, 99 1. YOUR JOB: Using the Node struct on the next page, write a C++ function which takes two such lists A and B and returns the set difference A-B as a new (sorted) list. Example: t 4, 6, 8, 12, 14, 18, 33, 37] 2 . u.G.1- [ 2. 4, 7, 8, 14, 15, 33, 44] [ 6, 12, 18, 37 A: A-B: RUNTIME REQUIREMENT : 0(IAI+IBI) (where IAI and IBI are the lengths of the two respective lists.) Things to think about/remember . Assume the lists are “well-formed”(they are sorted and contairn no duplicates) . The given lists are not modified (i.e., you will need to allocate nodes for the intersection list). nullptr represents the empty set . . Recursion might make things pretty straightforward. On the next page you will find a function stub. Note that the function is “static” meaning that it has no “calling object”. Also, the function operates at the “node-level” – there is no wrapper class with a front/back pointer struct Node int data; node next; static Nodedifference (Node A, Node B) Show transcribed image text QUESTION 1 (16 points)Suppose we are representing sets of integers with sorted singly-linked lists (sorted in ascendinq order). For example, consider this set: 12, 18, 3, -5, 99, 6 We would represent it as the linked list -5, 2, 3, 6, 18, 99 1. YOUR JOB: Using the Node struct on the next page, write a C++ function which takes two such lists A and B and returns the set difference A-B as a new (sorted) list. Example: t 4, 6, 8, 12, 14, 18, 33, 37] 2 . u.G.1- [ 2. 4, 7, 8, 14, 15, 33, 44] [ 6, 12, 18, 37 A: A-B: RUNTIME REQUIREMENT : 0(IAI+IBI) (where IAI and IBI are the lengths of the two respective lists.) Things to think about/remember . Assume the lists are “well-formed”(they are sorted and contairn no duplicates) . The given lists are not modified (i.e., you will need to allocate nodes for the intersection list). nullptr represents the empty set . . Recursion might make things pretty straightforward. On the next page you will find a function stub. Note that the function is “static” meaning that it has no “calling object”. Also, the function operates at the “node-level” – there is no wrapper class with a front/back pointer
struct Node int data; node next; static Nodedifference (Node A, Node B)
Expert Answer
Answer to QUESTION 1 (16 points)Suppose we are representing sets of integers with sorted singly-linked lists (sorted in ascendinq … . . .
OR

