MyLab Programming with Pearson eText -- Standalone Access Card -- for Starting Out With C++: Early Objects (My Programming Lab)
9th Edition
ISBN: 9780134379548
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 17, Problem 11PC
Program Plan Intro
Generation of Subsets
Program Plan:
- Include the required header files
- Declare function prototypes.
- Define the “main()” function.
- Declare the required variables.
- Get the input from the user.
- If the user input is not in the range the condition exits the program.
- Create the list and call the function “get_Subsets ()”.
- Display the output.
- Define the overloaded stream insertion operator for
vector of int.- Display the open square bracket.
- If the number is in the range, display the number inside the bracket.
- Display the close square bracket.
- Return the output to the main function.
- Define the overloaded stream insertion operator for a list of generic type.
- Display the open square bracket.
- Create a list and declare the variable name “itr” for the list.
- While condition used to check if the “itr” is not equal to last number in the same list.
- If so, display the number.
- Increment the “itr”.
- Print the numbers separated by commas.
- Display the close square bracket.
- Return the output to the main function.
- Define the “get_subsets” vector function.
- Declare the list of subsets
- Start with a list of subsets of 1 to n that contains on the empty set.
- The “if” condition is used to check if the “n” is greater than “k” value.
- Temporarily used to extend the subset list by declaring the vector variables.
- While condition used to check if the “itr” is not equal to last number in the same list.
- Declare the vector variables.
- Push the value to the list.
- Increment the “itr” value.
- Set the “sub_setList” variable with the “big_List” value.
- Return the value to the main function.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Consider a (singly) linked list. Describe an algorithm to remove every second element from the list.
(HINT: The algorithm is similar to the one that is used when we delete a single node. Here, we need to skip an element after every deletion, and then if we have not reached the end of the list repeat this procedure until the list is exhausted.).
(a) Write the steps to removeEverySecondElement from the linked list.
(b) Write a function removeEverySecondElement() that implements the task
Consider the following function that takes reference to head of a Doubly Linked List as parameter. Assume that anode of doubly linked list has previous pointer as prev and next pointer as next.void fun(struct node **head_ref){struct node *temp = NULL;struct node *current = *head_ref;while (current != NULL){temp = current->prev;current->prev = current->next;current->next = temp;current = current->prev;}if(temp != NULL )*head_ref = temp->prev;}Assume that reference of head of following doubly linked list is passed to above function 1 <--> 2 <--> 3 <--> 4 <--> 5 <-->6. What should be the modified linked list after the function call?
Note:
solve as soon as possible
Suppose you have two objects of Doubly Linked List D1 and D2. Each object is representing a different Doubly Linked List. Write a function to concatenate both doubly linked lists. The concatenation function must return the address of head node of concatenated Doubly Linked List, and it must take two Node* parameters. You need to keep in mind all exceptional cases for example what if either one of the doubly linked lists is empty? Perform this task on paper, take a clear picture of solution and paste it in answer section.
Chapter 17 Solutions
MyLab Programming with Pearson eText -- Standalone Access Card -- for Starting Out With C++: Early Objects (My Programming Lab)
Ch. 17.1 - Prob. 17.1CPCh. 17.1 - Prob. 17.2CPCh. 17.1 - Prob. 17.3CPCh. 17.1 - Prob. 17.4CPCh. 17.2 - Prob. 17.5CPCh. 17.2 - Prob. 17.6CPCh. 17.2 - Why does the insertNode function shown in this...Ch. 17.2 - Prob. 17.8CPCh. 17.2 - Prob. 17.9CPCh. 17.2 - Prob. 17.10CP
Ch. 17 - Prob. 1RQECh. 17 - Prob. 2RQECh. 17 - Prob. 3RQECh. 17 - Prob. 4RQECh. 17 - Prob. 5RQECh. 17 - Prob. 6RQECh. 17 - Prob. 7RQECh. 17 - Prob. 8RQECh. 17 - Prob. 9RQECh. 17 - Write a function void printSecond(ListNode ptr}...Ch. 17 - Write a function double lastValue(ListNode ptr)...Ch. 17 - Write a function ListNode removeFirst(ListNode...Ch. 17 - Prob. 13RQECh. 17 - Prob. 14RQECh. 17 - Prob. 15RQECh. 17 - Prob. 16RQECh. 17 - Prob. 17RQECh. 17 - Prob. 18RQECh. 17 - Prob. 1PCCh. 17 - Prob. 2PCCh. 17 - Prob. 3PCCh. 17 - Prob. 4PCCh. 17 - Prob. 5PCCh. 17 - Prob. 6PCCh. 17 - Prob. 7PCCh. 17 - Prob. 8PCCh. 17 - Prob. 10PCCh. 17 - Prob. 11PCCh. 17 - Prob. 12PCCh. 17 - Running Back Program 17-11 makes a person run from...Ch. 17 - Read , Sort , Merge Using the ListNode structure...
Knowledge Booster
Similar questions
- compare and contrast static array-based unsorted list and static array-based sorted list, There is a function binary search in the sorted list one. Which two public functions are using the binary search function so that it can be faster than utilizing a linear search?arrow_forwardLet xHead, yHead and zHead be the head pointers of 3 linked lists of integers (called X-list, Y-list and Z-list, respectively, from here). X-list and Y-list are each sorted (in non-decreasing order) in itself and each may be empty. Z-list is initially empty (i.e., zHead initially contains the null pointer). Develop and test a recursive C++ function called Merge2AscListsRecur that combines the nodes in X-list and Y-list into Z-list such that, after calling the function, Z-list is a sorted list (in non-decreasing order) containing all the nodes initially contained in X-list and Y-list – X-list and Y-list should both be empty after the call. Other specifications/requirements: ● Each node of the list has the following structure: struct Node{ int data; Node *link;}; ● The function should: ► Have only three parameters (each a pointer-to-Node) and no return value (be a void function). ► Not use any global variables or static local…arrow_forwardLet xHead, yHead and zHead be the head pointers of 3 linked lists of integers (called X-list, Y-list and Z-list, respectively, from here). X-list and Y-list are each sorted (in non-decreasing order) in itself and each may be empty. Z-list is initially empty (i.e., zHead initially contains the null pointer). Develop and test a recursive C++ function called SortedMergeRecur that combines the nodes in X-list and Y-list into Z-list such that, after calling the function, Z-list is a sorted list (in non-decreasing order) containing all the nodes initially contained in X-list and Y-list – X-list and Y-list should both be empty after the call. Other specifications/requirements: ● Each node of the list has the following structure: struct Node{ int data; Node *link;}; ● The function should: ► Have only three parameters (each a pointer-to-Node) and no return value (be a void function). ► Not use any global variables or static local…arrow_forward
- Sets are collections (1) without defined order and (2) not allowing duplication. Multisets, also called “bags” are collections without defined order but which permit duplication, i.e., more than one element. We define the function #(a B) to be the number of occurrences of the element a in the bag B. For example, #(1, [1 1 2 3 4 4 5]) is 2 and #(5, [1 1 2 3 4 4 5]) = 1. sum : List × List -> ListThis function should take as arguments two lists representing bags and should return the list representing the list resulting from simply appending the input lists together. Racket code only please. No loops Allowed: 1. define, let2. lambda3. cons, car, cdr, list, list?, append, empty?, length, equal?4. and, or, not5. if, cond7. +, -, /, * Thank you!arrow_forwardComputer Science please solve this problem as soon as possible Write a function to insert the element into the linked list the given number X. E.g., for a given set of integers, [2, 4, 12, 6, 5, 3], the linked list is 2->4->12->6->5->3. For a given number, (X=15), the count will be 11 that are (2,4), (2,12), (2,6), (2,5), (2,3), (4,6), (4,5), (4,3), (6,5), (6,3), (5,3).arrow_forwardImplement the following function that returns a vector of vectors of Item, each of which is a subset of elements chosen from the given vector a[first…last]: /* if a is {1,2,3}, first=0, last=2, the function shall returns a vector of the following vectors: {}, {1}, {2}, {3}, {1,2},{1,3}, {2,3},{1,2,3}, all subsets of a[0…2]. Precondition: last-first+1>=1, i.e., there is at least one element in the a[first…last] Note 1)if the length of a[first…last] is n, then the function should return a vector of 2n vectors 2) The order of these subsets does not need to match what’s listed here… */ vector<vector<int>> subsets (const vector<int> & a, int first, int last) codearrow_forward
- SOB 22 – (Block 2)Write up what the properties of sets, lists, vectors and strings are and whether they are mutable or immutable. Then consider the class of problems that they are best for and use some code to illustrate your points. E.g., if you have a function that solves a problem using lists, then you can say why you can/can’t use vectors for it or sets etc.arrow_forwardWhat are the properties of sets, lists, vectors, strings and are they mutable or immutable? What type of problems is each one best used for over the other type? E.g if I have a function that solves a problem using a list, why wouldn't I be able to use a vector or set for it? Can I have some code that shows this in Racket?arrow_forwardThis is in C++. I want to create a generic function increment(start, stop, x) that adds an integer x to every element in the range [start, stop) of a vector. The addition is done using the + operator.arrow_forward
- SOB 22 – (Block 2) Write up what the properties of sets, lists, vectors and strings are and whether they are mutable or immutable. Then consider the class of problems that they are best for and use some code to illustrate your points. E.g., if you have a function that solves a problem using lists, then you can say why you can/can’t use vectors for it or sets etc. Note: I need code examples.arrow_forwardTo add the two polynomials, assume that the singly linked lists' nodes are sorted in decreasing order of the variable x's exponents.The goal is to generate a new list of nodes representing the sum of P1 and P2. This is accomplished by combining the COEFF fields of nodes with identical powers of variable x in lists P1 and P2, and then creating a new node in the resultant list P1 + P2. The procedure's crux is presented below.P1 and P2 are the start pointers of the singly linked lists that represent polynomials P1 and P2. PTR1 and PTR2 are two temporary pointers that are initially set to P1 and P2, respectively. Make procedural code.arrow_forwardWrite an algorithm to implement the frequency count self-organizing list heuristic, assuming that the list is implemented using an array. In particular, write a function FreqCount that takes as input a value to be searched for and which adjusts the list appropriately. If the value is not already in the list, add it to the end of the list with a frequency count of one. Write an algorithm to implement the move-to-front self-organizing list heuristic, assuming that the list is implemented using an array. In particular, write a function MoveToFront that takes as input a value to be searched for and which adjusts the list appropriately. If the value is not already in the list, add it to the beginning of the list. Write an algorithm to implement the transpose self-organizing list heuristic, assuming that the list is implemented using an array. In particular, write a function Transpose that takes as input a value to be searched for and which adjusts the list appropriately. If the…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning