Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
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
Introduction
For this assignment, you are to write a program which implements a Sorted List data structure using a circular
array-based implementation and a driver program that will test this implementation.
The Sorted List ADT is a linear collection of data in which all elements are stored in sorted order. Your
implementation has to store a single int value as each element of the list and support the following operations:
1. add(x) – adds the integer x to the list. The resulting list should remain sorted in increasing order. The time
complexity of this operation should be 0(N), where N is the size of the list.
2. removefirst() - deletes the first integer from the list and returns its value. The remaining list should
remain sorted. Time complexity of this operation should be 0(1).
3. removelast() – deletes the last integer from the list and returns its value. The remaining list should
remain sorted. Time complexity of this operation should be 0(1).
4. exists(x) – returns true if the…
Code in C. Solve the code below.
Write a function that takes a vector of integers, an integer n representing the number of elements in that vector, and an integer b. Implement the sequential search algorithm to look for the integer b in the vector. The sequential search works as follows: you must look at all the elements of the vector until you find the b, from the first to the last. The function must return an integer representing how many elements the function tested until it found b. If it does not find the function, it must return 0. The name of the function must be called "busca_seq".
int busca_seq(int vetor[], int n, int b)
{
//your code
}
My Code
#include<stdio.h>
int busca_seq(int vetor[], int n, int b)
{
int i;
for(i = 0; i < n; i++){
if(vetor[i] == b)
return (i+1);
}
{
int vet[5],n = 5,b,x;
vet[0] = 1;
vet[1] = 2;
vet[2] = 3;
vet[3] = 4;
vet[4] = 5;
scanf("%d",&b);
x = busca_seq(vet,n,b);
printf("%d",x);
return 0;
}
}
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
Starting Out with C++: Early Objects (9th Edition)
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
- Create a function set(v, i, j) that makes vector v contain the integers i through j. The original contents of v is deleted. The vector is left empty ifj < i. The argument v is a vector of integers.arrow_forwardCode in C. Solve the code below. write a function that receives a vector of integers already sorted in ascending order, an integer n represents the number of elements in this vector, and an integer b. Implement the sequential search algorithm to look for the integer b in the vector. The binary search works as follows: you must look for the element in the position exactly in the half of the vector, if for the searched it returns the number of tests done so far, if not for the searched, calculate the midpoint of the half of the vector after assess whether the searched value is greater or less than the value at the middle position. Not finding the value searched, the function must return 0. The name of the function will be called "busca_bin". int busca_bin (int vetor [ ], int n, int b){ #include <stdio.h> int busca_bin(int vetor[] , int n , int a) { int s1 = 0; int s2 = n-1; int pass = 0; int s3; while(s1<s2) { s3 = (s1+s2)/2; pass++;…arrow_forwardCode in C. Solve the code below. write a function that receives a vector of integers already sorted in ascending order, an integer n represents the number of elements in this vector, and an integer b. Implement the sequential search algorithm to look for the integer b in the vector. The binary search works as follows: you must look for the element in the position exactly in the half of the vector, if for the searched it returns the number of tests done so far, if not for the searched, calculate the midpoint of the half of the vector after assess whether the searched value is greater or less than the value at the middle position. Not finding the value searched, the function must return 0. The name of the function will be called "busca_bin". int busca_bin (int vetor [ ], int n, int b){ #include <stdio.h> int busca_bin(int vetor[] , int n , int a) { int s1 = 0; int s2 = n-1; int pass = 0; int s3; while(s1<s2) { s3 = (s1+s2)/2; pass++;…arrow_forward
- Code in C. Solve the code below. write a function that receives a vector of integers already sorted in ascending order, an integer n represents the number of elements in this vector, and an integer b. Implement the sequential search algorithm to look for the integer b in the vector. The binary search works as follows: you must look for the element in the position exactly in the half of the vector, if for the searched it returns the number of tests done so far, if not for the searched, calculate the midpoint of the half of the vector after assess whether the searched value is greater or less than the value at the middle position. Not finding the value searched, the function must return 0. The name of the function will be called "busca_bin". int busca_bin (int vetor [ ], int n, int b){// your code} My code #include <stdio.h> int busca_bin(int vetor[] , int n , int a) { int s1 = 0; int s2 = n-1; int pass = 0; int s3; while(s1<s2) {…arrow_forward1. a function that takes in a list (L), and creates a copy of L. note: The function should return a pointer to the first element in the new L. [iteration and recursion]. 2. a function that takes in 2 sorted linked lists, and merges them into a single sorted list. note: This must be done in-place, and it must run in O(n+m).arrow_forwardLet A and B be two integers valued arrays of sizes n1 & n2 respectively. The elements of the two arrays are sorted in increasing order and may contain duplicate elements.It is required to form a list, C, of distinct elements, in increasing order, that are in A but not in B and in B but not in A. (There shall be no duplicate elements in list C.)The two arrays, A & B, can only be traversed once.Example:A: -2, 2, 4, 4, 4, 7, 9, 9, 9, 12, 15,B: 1, 2, 5, 9, 15, 15, 15, 17, 17, 17C: -2, 1, 4, 5, 7, 12, 17arrow_forward
- QUESTION: NOTE: This assignment is needed to be done in OOP(c++/java), the assignment is a part of course named data structures and algorithm. A singly linked circular list is a linked list where the last node in the list points to the first node in the list. A circular list does not contain NULL pointers. A good example of an application where circular linked list should be used is a items in the shopping cart In online shopping cart, the system must maintain a list of items and must calculate total bill by adding amount of all the items in the cart, Implement the above scenario using Circular Link List. Do Following: First create a class Item having id, name, price and quantity provide appropriate methods and then Create Cart/List class which holds an items object to represent total items in cart and next pointer Implement the method to add items in the array, remove an item and display all items. Now in the main do the following Insert Items in list Display all items. Traverse…arrow_forwardWrite a function called genericSort() that takes in a numeric or integer vector, sorts it, and returns the indices of the sorted values. It should also print an error if the input is a character. For example, genericSort(c(1,3,7,5)) should return the vector (1,2,4,3). Programming in Rarrow_forwardcan you write in C++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