Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
def remove_occurences[T](xs:List[T], elem: T, n:Int) : List[A]
= {}
Using the function above, can you show me how to make a polymorphic function in scala where the program removes elem , n number of times from the list. If n > elem then remove all elem from the list
For example:
remove_occurences(List(4,5,6,7,4),4,1) -> List(5,6,7,4)
remove_occurences(List(4,5,6,7,4),4,2) -> List(5,6,7)
remove_occurences(List(4,5,6,7,4),2,2) -> List(4,5,6,7,4)
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Write a function inde which returns the index (start from 1) of the occurrence of a given value. Use helper function. Two functions are enough.inde(1, [1,2,1,1,2,2,1]) → [1,3,4,7] Write a function nele which repeats each element in a list n times. Use helper function. Two functions only.nele([1,2],3) → [1,1,1,2,2,2] Write a function isfact to determine if a positive integer is a factorial number. Do not use any formula such as T(n)=n(n+1)/2. Do it in recursive fashion. Two functions are enough.isfact(120) → truearrow_forwarddef reverse_list (1st: List [Any], start: int, end: int) -> None: """Reverse the order of the items in list , between the indexes and (including the item at the index). If start or end are out of the list bounds, then raise an IndexError. The function must be implemented **recursively**. >>> lst ['2', '2', 'v', 'e'] >>>reverse_list (lst, 0, 3) >>> lst ['e', 'v', 'i', '2'] >>> lst [] >>>reverse_list (lst, 0, 0) >>> lst [0] >>> Ist = [] >>> reverse_list (lst, 0, 1) Traceback (most recent call last): IndexError #1 #1arrow_forward} (1 of 3 parts) Consider the function below that is given the head and tail pointers to a double linked list. bool patronum (Node ✶h, Node * t) { bool c = true; if (t nullptr) return true; Node* p = t; while (p != h) { Node* j = p; Node* r = p->prev; EXAM for (Node* r = p->prev; r != nullptr; r = r->prev) { if (j->value > r->value) { c = false; j = r; } swap(p->value, j->value); p = p->prev; return c;arrow_forward
- JavaScript Given a singly linked list of integers, determine whether or not it's a palindrome. // Singly-linked lists are already defined with this interface: // function ListNode(x) { // this.value = x; // this.next = null; // } // function isListPalindrome(head) { } Note: in examples below and tests preview linked lists are presented as arrays just for simplicity of visualization: in real data you will be given a head node l of the linked list Example For l = [0, 1, 0], the output should beisListPalindrome(l) = true; For l = [1, 2, 2, 3], the output should beisListPalindrome(l) = false.arrow_forwardSuppose a node of a linked list is defined as follows in your program: typedef struct{ int data; struct Node* link; } Node; Write the definition of a function, printOdd(), which displays all the odd numbers of a linked list. What will be the time complexity of printOdd()? Express the time complexity in terms of Big-O notation.arrow_forwardPythonarrow_forward
- Double linked list in Java Double linked list Textbook reference Data structures and algorithms Micheal Goodricharrow_forwardExercise G -- Implement a function halves that takes a list of integers and divides each element of the list by two (using the integer division operator //) NOTE use the map function combined with a lambda expression to do the division with a neat solution halves : List Int -> List Int halves xs = [ ] --remove this line and implement your halves function herearrow_forwardConsider the following function:int enigma(NodeInt32* node){if(node == NULL)return 0; elsereturn 1 + enigma(node->next);} Which best describes the enigma function?A. The function performs a binary search of a list. B. The function computes the length of a list. C. The function sorts a list. D. None of the above.arrow_forward
- C++ Create a generic function increment(start, stop, x) that adds x to every element in the range [start,stop). The addition is done using the + operator. The arguments start and stop are bidirectional iterators. Write a test driver.arrow_forwardConsider the following function access_element_by_index that returns the iterator to the element at the index i in the list l. typedef std::list<int> int_list; int_list::iterator access_element_by_index(size_t I, int_list &) { assert( ? ); … } Assume the first element of the list is at the index 0, the second at the index 1, and so on. If the function is required to return an iterator that can be dereferenced, determine the precondition of the function, and write an assertion to validate it. (You don’t need to implement the functions).arrow_forward3. Write the remove_evens() function that receives a list of integers as a parameter and returns a new list of integers containing only the odd numbers from the original list. Ex1) If n = [1, 2, 3, 4, 5, 6], remove_evens(n) returns [1, 3, 5]. Ex2) If n = [2, 4, 8], remov move_evens(n) returns [].arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education