0% found this document useful (0 votes)
13 views2 pages

Recursion program to print all permutations of a strings

Recursion program solution

Uploaded by

Dilip Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Recursion program to print all permutations of a strings

Recursion program solution

Uploaded by

Dilip Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Recursion program

Permutation of all characters of a string

class Main {
{ swap(chars, currentIndex, i);
// Utility function to swap two permutations(chars,
characters in a character array currentIndex + 1);
private static void swap(char[] swap(chars, currentIndex, i);
chars, int i, int j) }
{ }
char temp = chars[i];
chars[i] = chars[j]; public static void
chars[j] = temp; findPermutations(String str) {
}
// base case
// Recursive function to generate all if (str == null || str.length() == 0)
permutations of a string {
private static void return;
permutations(char[] chars, int }
currentIndex)
{ permutations(str.toCharArray(),
if (currentIndex == chars.length - 0);
1) { }
System.out.println(String.value
Of(chars)); // generate all permutations of a
} string in Java
public static void main(String[] args)
for (int i = currentIndex; i < {
chars.length; i++) String str = "ABC";
findPermutations(str);
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy