EBK PROBLEM SOLVING WITH C++
9th Edition
ISBN: 9780133834505
Author: SAVITCH
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 17, Problem 2P
Program Plan Intro
Template version of the iterative binary search
Program Plan:
- Include the required libraries
- Define a constant variable
- Define a template for iterative search method
- Define main method
- Declare the required variables
- Get the number that is to be located from user
- Search the element using the if condition
- Print the result
- Define a template for iterative search method
- Declare the required variables
- If the element is not present in the array
- Find out the middle element in the array
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a generic class that stores two elements of the same type and can tell the user which one is the larger between the two. The type of the two elements should be parameterized and the class should have a function called “maxElement” that returns the larger element.
write this java code
6.2 Create a Product class with Product Id & Product Name. Write a program to accept information of 10 products and store that in HashSet. Do following operations, a.Search a particular product in the HashSet.b.Remove a particular product from the HashSet by using product id.(Referbelow table for the product list)
Product Id Product Name
P001 Maruti 800
P002 Maruti Zen
P003 Maruti Dezire
P004 Maruti Alto
Implement a __setitem__ function that also supports negative indices. For example:
W = L2(Node(10, Node(20, Node(30))))print W[ 10, 20, 30 ]
W[1]=25print W[ 10, 25, 30 ]
W[-1]=35print W[ 10, 25, 35 ]
Complete the code:
def L2(*args,**kwargs): class L2_class(L): def __getitem__(self, idx): <... YOUR CODE HERE ...> def __setitem__(self, idx, value): <... YOUR CODE HERE ...> return L2_class(*args,**kwargs)
W = L2(Node(10, Node(20, Node(30))))print(W)W[1]=25print(W)W[-1]=35print(W)
Chapter 17 Solutions
EBK PROBLEM SOLVING WITH C++
Ch. 17.1 - Write a function template named maximum. The...Ch. 17.1 - Prob. 2STECh. 17.1 - Define or characterize the template facility for...Ch. 17.1 - Prob. 4STECh. 17.1 - Display 7.10 shows a function called search, which...Ch. 17.1 - Prob. 6STECh. 17.2 - Give the definition for the member function...Ch. 17.2 - Give the definition for the constructor with zero...Ch. 17.2 - Give the definition of a template class called...Ch. 17.2 - Is the following true or false? Friends are used...
Ch. 17 - Write a function template for a function that has...Ch. 17 - Prob. 2PCh. 17 - Prob. 3PCh. 17 - Redo Programming Project 3 in Chapter 7, but this...Ch. 17 - Display 17.3 gives a template function for sorting...Ch. 17 - (This project requires that you know what a stack...Ch. 17 - Prob. 6PPCh. 17 - Prob. 7PPCh. 17 - This project requires that you complete...
Knowledge Booster
Similar questions
- How does a map tell us when an element is not found? A The map returns a null reference. B The map throws an exception. C The map returns an empty data object. D The map returns a value of zero.arrow_forwardDevelop a class ResizingArrayQueueOfStrings that implements the queueabstraction with a fixed-size array, and then extend your implementation to use arrayresizing to remove the size restriction.Develop a class ResizingArrayQueueOfStrings that implements the queueabstraction with a fixed-size array, and then extend your implementation to use arrayresizing to remove the size restriction.arrow_forwardWrite a template version of the iterative binary search algorithm from Display 13.8 which only searches an array of integers for an integer key. Specify requirements on the template parameter type. Discuss the requirements on the template parameter type.arrow_forward
- Write a program to test various operations of the class doublyLinkedList.arrow_forwardThere’s a somewhat imperfect analogy between a linked list and a railroad train, where individual cars represent links. Imagine how you would carry out various linked list operations, such as those implemented by the member functions insertFirst(), removeFirst(), and remove(int key) from the LinkList class in this hour. Also implement an insertAfter() function. You’ll need some sidings and switches. You can use a model train set if you have one. Otherwise, try drawing tracks on a piece of paper and using business cards for train cars.arrow_forward1. Write the statement that will add an association of a person named “John” and the college called “Middlesex” in the Map called friends. 2. Given the following code fragments, identify if an exception is thrown and what is that exception.a.) Map<String, String> m = new HashMap<String, String>( );String obj = m.get(“hello”); b.) String str = " ";Set<String> s = new HashSet<String>( );s.add(“The”);s.add(“rain”);s.add(“in”);s.add(“New Jersey”);for (Iterator<String> i = s.iterator( ); i.hasNext( );)str = str + (Integer) i.next( );arrow_forward
- A) Consider the generic print() method, write a method that takes an array of E, where E must be Comparable or extend a type that is Comparable, and returns a reference to the greatest object in the array. In this case, the greatest value is one for which compareTo() would return 0 or more for any other object in the array. If there is more than one possible largest value (these would have to be equal to each other but greater than any other objects in the array), it does not matter which one you choose. B) Write a generic Java queue class (a plain queue, not a priority queue). Call it GenericQueue, because the JDK already has an interface called Queue. The class must be able to create a queue of objects of any reference type. Consider the GenericStack class shown in the lecture notes for some hints. Like the Stack, the GenericQueue should use an underlying ArrayList<E>. Write these methods and any others you find useful: enqueue() adds an E to the queue peek() returns a…arrow_forwardExtend the class linkedListType by adding the following operations:a. Write a function that returns the info of the kth element of the linkedlist. If no such element exists, terminate the program.b. Write a function that deletes the kth element of the linked list. If nosuch element exists, output an appropriate message. Provide the definitions of these functions in the class linkedListType. Also writea program to test these functions. (Use either the classunorderedLinkedList or the class orderedLinkedList to testyour function.) Note: Code in c++arrow_forwardWrite a class that maintains the top 10 scores for a game application, implementthe add and remove functions. use a singlylinked list instead of an array. C++ C++ C++arrow_forward
- Create the set objects A={L,M,N,P,Q} and B={L,R,S,P,T } .arrow_forwardYou are going to implement a program that creates an unsorted list by using a linked list implemented by yourself. NOT allowed to use LinkedList class or any other classes that offers list functions. It is REQUIRED to use an ItemType class and a NodeType struct to solve this. Use C++, please read instructions carefully and new solution only! The “data.txt” file has three lines of data 100, 110, 120, 130, 140, 150, 160 100, 130, 160 1@0, 2@3, 3@END You need to 1. create an empty unsorted list 2. add the numbers from the first line to list using putItem() function. Then print all the current keys to command line in one line using printAll(). 3. delete the numbers given by the second line in the list by using deleteItem() function. Then print all the current keys to command line in one line using printAll().. 4. putItem () the numbers in the third line of the data file to the corresponding location in the list. For example, 1@0 means adding number 1 at position 0 of the list. Then…arrow_forwardWrite a short IO function, runTest, which runs your tests using quickCheck. runTest = undefined --Consider the following type which allows non-homogenous lists to be built. data MkType a b = ElemA a (MkType a b) | ElemB b (MkType a b) | Emptyderiving Showarrow_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