here's the java implementation
package removeduplicates;
import java.io.*;
/**
*
* @author UmerFarooq
*/
public class Main {
/**
* @param args the command line arguments
*/
public static char[] input;
public static void remDep(int i, int j)
{
if (j<0)
return;
else if (input[i] == input[j])
input[i] = ' ';
remDep(i,j-1);
}
public static void compDel(int i)
{
if (i >= input.length)
return;
else {
remDep(i, i-1);
compDel(i+1);
}
}
public static void main(String[] args) {
// TODO code application logic here
try{
File f = new File("input.txt");
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String s = new String();
while ((s=br.readLine())!=null)
{
input = new char[s.length()];
input = (s.toCharArray());
compDel(1);
for (int i = 0; i < input.length; i++)
if (input[i] != ' ')
System.out.print(input[i]);
}
System.out.println("");
br.close();
}
catch(IOException io)
{
System.out.println("here");
}
}
}
On Sat, Sep 18, 2010 at 10:42 PM, jagadish <[email protected]> wrote:
> You are given a string which is sorted.. Write a recursive function to
> remove the duplicate characters in the string.
> eg: potatoeos
> output: potaes
> NO extraspace like hash/ bitmaps..
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
--
Umer
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.