MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / permute

Method permute

StringPermutations.java:16–36  ·  view source on GitHub ↗
(int index, String s)

Source from the content-addressed store, hash-verified

14 return String.valueOf(ch);
15 }
16 public static void permute(int index, String s)
17 {
18 // bASE
19 if(index==s.length()-1)
20 {
21 System.out.println(s);
22 return;
23 }
24
25 // logic
26 for(int i=index;i<s.length();i++)
27 {
28 // swap
29 s=swap(s,i,index);
30 // recursion
31 permute(index+1,s);
32 // backtrack
33 s=swap(s,i,index);
34 }
35
36 }
37}

Callers 1

mainMethod · 0.95

Calls 1

swapMethod · 0.95

Tested by

no test coverage detected