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
Question
Need help with this c++ recursive function:
Write the function starCrossed() which computes (recursively, with no loops) a new string where identical characters that are adjacent in the original string are separated from each other by a "*".
Here are some examples:
- starCrossed("hello") returns "hel*lo"
- starCrossed("xxyy") returns "x*xy*y"
- starCrossed("aaaa") returns "a*a*a*a"
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 3 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 recursive function called Rev takes a string argument (str) and and integerargument(i – the initial string position). Rev prints the str in reverse. You may not useany built-in reverse function or method. You may use string’s length method.arrow_forwardMake a code using Recursion The countSubstring function will take two strings as parameters and will return an integer that is the count of how many times the substring (the second parameter) appears in the first string without overlapping with itself. This method will be case insensitive. For example: countSubstring(“catwoman loves cats”, “cat”) would return 2 countSubstring(“aaa nice”, “aa”) would return 1 because “aa” only appears once without overlapping itself. public static int countSubstring(String s, String x) { if (s.length() == 0 || x.length() == 0) return 1; if (s.length() == 1 || x.length() == 1){ if (s.substring(0,1).equals(x.substring(0,1))){ s.replaceFirst((x), " "); return 1 + countSubstring(s.substring(1), x); } else { return 0 + countSubstring(s.substring(1), x); } } return countSubstring(s.substring(0,1), x) + countSubstring(s.substring(1), x); } public class Main { public static void main(String[] args) {…arrow_forwardWrite a recursive function to see if the first letter matches the last letter, return the middle letters and check until only 0 or 1 letters are left. It returns True or False. Here is the original code that needs to be checked: # Returns the first character of the string str def firstCharacter(str): return str[:1] # Returns the last character of a string str def lastCharacter(str): return str[-1:] # Returns the string that results from removing the first # and last characters from str def middleCharacters(str): return str[1:-1] def isPalindrome(str): # base case #1 # base case #2 # recursive case pass Python codearrow_forward
- python lab Write a recursive function named reverse that accepts a string argument and returns the original string with its characters reversed. For example, calling reverse ('goodbye') would return 'eybdoog'. The function must use recursion to reverse the characters in the string. Do not use a loop.arrow_forwardcode neededarrow_forwardin c++arrow_forward
- Please solve this in C programming language as early as possible. .Write a recursive function that can use to add all the numbers from 5 to n, where n>5. n will be given by the user. Prototype: int add_num(int n);arrow_forwardin c++ with pre and post pseudocode please dont show me the same code from others please thank u Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which Takes an array of integers and its size as input params and returns a bool such that 'true' ==> all elements of the array are prime, so the array is prime, 'false' ==> at least one element in array is not prime, so array is not prime. Print out a message "Entering <function_name>" as the first executed statement of each function. Perform the code to test whether every element of the array is a Prime number. Print out a message "Leaving <function_name>" as the last executed statement before returning from the function. Remember - there will be nested loops for the iterative function and there can be no loops at all in the recursive function.…arrow_forwardWrite a recursive function that displays a string reversely on the console using the following header: def reverseDisplay(value):For example, reverseDisplay("abcd") displays dcba. Write a test programthat prompts the user to enter a string and displays its reversal.arrow_forward
- language: Python Problem: Write a recursive function reverse(sentence) for reversing a sentence. For example, reverse('Who let the dogs out?') will return '?tuo sgod eht tel ohW'. Also write a test case in the program to prove the function given works.arrow_forwardNeed help Writing a function, countVowels, that accepts a string as an argument. countVowels should return the number of vowels in that string. Use recursion. example countVowels('Four score and seven years'); // => 9arrow_forwardwrite a recursive function that checks see if the first letter matches the last letter, return the middle letters and check until only 0 or 1 letters are left. It returns True or False. Here is python code that needs to be fixed # Returns the first character of the string str def firstCharacter(str): return str[:1] # Returns the last character of a string str def lastCharacter(str): return str[-1:] # Returns the string that results from removing the first # and last characters from str def middleCharacters(str): return str[1:-1] def isPalindrome(str): # base case #1 # base case #2 # recursive case pass def isPalindrome(string): reversedString = string[::-1] if reversedString == string: return True else: return False inputString = input() string = inputString.replace(" ", "") if isPalindrome(string): print(inputString,"is a palindrome") else: print(inputString,"is not a palindrome") if __name__ ==…arrow_forward
arrow_back_ios
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