13
votes
13answers
23k views

Whats the best way to recursively reverse a string in Java?

I have been messing around with recursion today. Often a programming technique that is not used enough. I set out to recursively reverse a string. Here's what I came up with: //A method to reverse a ...
0
votes
4answers
2k views

How can I find the longest word in a string recursively?

Finished, thanks everyone. Here's the revised code. public static String longestWord(String sentence) { String longest; int i = sentence.indexOf(' '); if (i == -1) { return ...
4
votes
8answers
9k views

Reversing a String - Recursion - Java

So here is the code I found to reverse a string recursively...and I think I understand how it is working, but I just want to know if someone could provide an explanation of it? public static String ...
1
vote
2answers
2k views

Using Recursion To Compare Strings To Determine Which Comes First Alphabetically Java

I am trying to write a method that uses recursion to compare the strings str1 and str2 and determine which of them comes first alphabetically (i.e., according to the ordering used for words in a ...
0
votes
4answers
2k views

How to return a string from char[] array using recursion loop.(java)

I am very bed in recursion... I need to convert a char[] array by using recursion loop only, into string. Without using for(),while()... loops. For example if i have char array: a[0]='H', a[1]='e', ...
8
votes
4answers
594 views

Recursive function to match a string against a wildcard pattern

So I've been trying to solve this assignment whole day, just can't get it. The following function accepts 2 strings, the 2nd (not 1st) possibly containing *'s (asterisks). An * is a replacement for a ...
5
votes
5answers
1k views

Substring recursive algorithm not working

I'm a programming student in my first C++ class, and recently we were encouraged to write a simple recursive function to find the first occurrence of a substring in a given string. If found, it ...
4
votes
3answers
184 views

Mapping sub-sets of parentheses to chars

I am attempting to create a Scala method that will take one parent group of parentheses, represented as a String, and then map each subgroup of parentheses to a different letter. It should then put ...
3
votes
3answers
3k views

C++ recursive permutation algorithm for strings -> not skipping duplicates

I'm having trouble finding a simple statement to skip the duplicates for this recursive permutation code. I've looked everywhere and seem to only find examples using swap or java. From what I gather, ...
2
votes
4answers
5k views

Python reversing a string using recursion

I want to use recursion to reverse a string in python so it displays the characters backwards (i.e "Hello" will become "olleh"/"o l l e h". I wrote one that does it iteratively: def Reverse( s ): ...
2
votes
1answer
477 views

Finding matching phrases between two pieces of text?

My objective is to find similar phrases from two pieces of text. I know that common words will be a problem. For example, and the we are the. In that case, I think a filter will be necessary. I want ...
1
vote
5answers
2k views

Counting vowels in a string using recursion

In my python class we are learning about recursion. I understand that it's when a function calls itself, however for this particular assignment I can't figure out how exactly to get my function to ...
1
vote
2answers
669 views

how to uncompress a given string in java recursively?

this is very easy using iteration but i have to do this using recursion. I tried to keep a count of how many times a char occurs in a string, the position and the rest of the string and output. ...
0
votes
1answer
131 views

The recursive method which will determine whether or not two strings match. The matching process should allow “wild cards”. A '@' and a '*'

the recursive method match(String x, String y) in the code below which will determine whether or not two strings match. The matching process should allow "wild cards". A '@' character will match with ...
0
votes
1answer
168 views

Recursion String in Java and removing characters

Here is what I have so far, but DrJava doesnt seem to compile it. It is supposed to print out "!olleH".. and I keep getting these errors: cannot find symbol : class Sentence, cannot find symbol : ...
0
votes
3answers
216 views

Reversing a string in c with recursion

I have written code to reverse a string in c... it works fine but I can't return the reversed string in the main() function. #include<stdio.h> main() { char a[17]="abcdefg"; reverse(a); ...
0
votes
2answers
317 views

Generating character combination in a string doesn't work entirely, why?

I'm trying to generate all combinations of the characters in a string. So the first parameter is the string given and the second parameter is the number of letters. So combinations("ab",2) should give ...
0
votes
1answer
450 views

XSLT 1.0 - Find text combination in element value recursively

I am not able to get this working, so need some help... My xml looks like <tag>PV1FEPMEDIRSPT530000030412011-04-08OC.CF.QL0000 ...