Re: [algogeeks] Permutations of a string

2012-05-07 Thread Sairam Ravu
Somebody please help me!! -- With love and regards, Sairam Ravu I M.Tech(CS) Sri Sathya Sai Institute of Higher Learning To live life, you must think it, measure it, experiment with it, dance it, paint it, draw it, and calculate it -- You received this message because you are subscribed to

Re: [algogeeks] Permutations of a string

2012-05-07 Thread Akshay Rastogi
private static void swap(char[] str, int i,int j) { char temp = str[i]; str[i] = str[j]; str[j] = temp; } private static void permute (char[] str, int strCurrIndex) { if (strCurrIndex == (str.length-1)) { System.out.println(str);

[algogeeks] Re: Permutations of a string

2012-05-07 Thread Sairam
Thanks for ur clean Code!! But you haven't considered the case of repeating characters in a string -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit

Re: [algogeeks] Re: Permutations of a string

2012-05-07 Thread Victor Manuel Grijalva Altamirano
In c++ use next_permutation(); o search in book of cormen... 2012/5/7 Sairam ravu...@gmail.com Thanks for ur clean Code!! But you haven't considered the case of repeating characters in a string -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

RE: [algogeeks] Permutations of a string

2012-05-07 Thread abhishek
http://www.geeksforgeeks.org/archives/767 just look into url -Original Message- From: algogeeks@googlegroups.com [mailto:algogeeks@googlegroups.com] On Behalf Of Sairam Ravu Sent: Monday, May 07, 2012 12:59 PM To: algogeeks@googlegroups.com Subject: Re: [algogeeks] Permutations of a

[algogeeks] Re: Permutations of a string

2012-05-07 Thread Gene
You just need to make sure that the same character is never swapped to the same position twice. Here is one way to do it. #include stdio.h #include string.h void swap(char *s, int i, int j) { char t = s[i]; s[i] = s[j]; s[j] = t; } void permute(char *s, int n) { if (s[n]) { int i;

Re: [algogeeks] Re: Sorting in O(n)

2012-05-07 Thread atul anand
@arpit : why algo subtracts 1 from each number of the input? On Sun, May 6, 2012 at 12:02 AM, Arpit Gupta arpitgupta.211...@gmail.comwrote: 1) Substract 1 from each no. 2) Now after substracting 1 from each no, convert it to base n. for example for n=6,the number 36 will be converted to 55.

Re: [algogeeks] Re: Sorting in O(n)

2012-05-07 Thread atul anand
@arpit : your formula for converting base 10 to base n is bit wrong , right formula should be :- let given base 10 no is m and we need to convert it in base n. then base n converted no is ( (m/n) * 10) + (m%n) ie 34 base 10 in base 6 is ((34/6)*10) + (34%6) ie 54 On Sun, May 6, 2012 at 10:20