btw, if u rn't suppose to use any extra space, then u should be going for
iterative solution; since recursion uses extra space by default.

On Sat, Sep 18, 2010 at 11:33 PM, Umer Farooq <the.um...@gmail.com> wrote:

> 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 <jagadish1...@gmail.com> 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 algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
> Umer
>



-- 
Umer

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to