Permutation with spaces

Here given code implementation process.

// C program  
// Permutation with spaces 
#include <stdio.h>
#include <string.h>

// Perform of permutation with include space between characters
void spacePermutation(const char *str, char result[], int n, int i, int j)
{
	if (i == n)
	{
		// Display permutation
		for (int k = 0; k < n *2; ++k)
		{
			printf("%c", result[k]);
		}
		// Include new line
		printf("\n");
		return;
	}
	// Include str element
	result[j] = str[i];
	// Find next permutation Through by recursion
	spacePermutation(str, result, n, i + 1, j + 1);
	// Include space
	result[j] = ' ';
	// Include str element
	result[j + 1] = str[i];
	// Find next permutation Through by recursion
	spacePermutation(str, result, n, i + 1, j + 2);
}
// Handles the request of finding permutation 
void permutation(const char *str)
{
	// Get the size
	int n = strlen(str);
	// This is used to store result
	char result[n *2];
	// Set initial value
	for (int i = 0; i < n *2; ++i)
	{
		if (i < n)
		{
			result[i] = str[i];
		}
		else
		{
			// Append the space character at last
			result[i] = ' ';
		}
	}
	spacePermutation(str, result, n, 1, 1);
}
int main()
{
	const char *str = "SETTING";
	permutation(str);
	return 0;
}

Output

SETTING
SETTIN G
SETTI NG
SETTI N G
SETT INGG
SETT IN G
SETT I NG
SETT I N G
SET TING G
SET TIN GG
SET TI NGG
SET TI N G
SET T INGG
SET T IN G
SET T I NG
SET T I N G
SE TTINGN G
SE TTIN G G
SE TTI NG G
SE TTI N GG
SE TT INGGG
SE TT IN GG
SE TT I NGG
SE TT I N G
SE T TING G
SE T TIN GG
SE T TI NGG
SE T TI N G
SE T T INGG
SE T T IN G
SE T T I NG
SE T T I N G
S ETTING N G
S ETTIN GN G
S ETTI NGN G
S ETTI N G G
S ETT INGG G
S ETT IN G G
S ETT I NG G
S ETT I N GG
S ET TING GG
S ET TIN GGG
S ET TI NGGG
S ET TI N GG
S ET T INGGG
S ET T IN GG
S ET T I NGG
S ET T I N G
S E TTINGN G
S E TTIN G G
S E TTI NG G
S E TTI N GG
S E TT INGGG
S E TT IN GG
S E TT I NGG
S E TT I N G
S E T TING G
S E T TIN GG
S E T TI NGG
S E T TI N G
S E T T INGG
S E T T IN G
S E T T I NG
S E T T I N G
/*
  Java Program for
  Permutation with spaces 
*/
class Permutations
{
	// Perform of permutation with include space between characters
	public void spacePermutation(String str, char[] result, int n, int i, int j)
	{
		if (i == n)
		{
			// Display permutation
			for (int k = 0; k < n * 2; ++k)
			{
				System.out.print(result[k]);
			}
			// Include new line
			System.out.print("\n");
			return;
		}
		// Include str element
		result[j] = str.charAt(i);
		// Find next permutation Through by recursion
		spacePermutation(str, result, n, i + 1, j + 1);
		// Include space
		result[j] = ' ';
		// Include str element
		result[j + 1] = str.charAt(i);
		// Find next permutation Through by recursion
		spacePermutation(str, result, n, i + 1, j + 2);
	}
	// Handles the request of finding permutation 
	public void permutation(String str)
	{
		// Get the size
		int n = str.length();
		// This is used to store result
		char[] result = new char[n * 2];
		// Set initial value
		for (int i = 0; i < n * 2; ++i)
		{
			if (i < n)
			{
				result[i] = str.charAt(i);
			}
			else
			{
				// Append the space character at last
				result[i] = ' ';
			}
		}
		spacePermutation(str, result, n, 1, 1);
	}
	public static void main(String[] args)
	{
		Permutations task = new Permutations();
		String str = "SETTING";
		task.permutation(str);
	}
}

Output

SETTING
SETTIN G
SETTI NG
SETTI N G
SETT INGG
SETT IN G
SETT I NG
SETT I N G
SET TING G
SET TIN GG
SET TI NGG
SET TI N G
SET T INGG
SET T IN G
SET T I NG
SET T I N G
SE TTINGN G
SE TTIN G G
SE TTI NG G
SE TTI N GG
SE TT INGGG
SE TT IN GG
SE TT I NGG
SE TT I N G
SE T TING G
SE T TIN GG
SE T TI NGG
SE T TI N G
SE T T INGG
SE T T IN G
SE T T I NG
SE T T I N G
S ETTING N G
S ETTIN GN G
S ETTI NGN G
S ETTI N G G
S ETT INGG G
S ETT IN G G
S ETT I NG G
S ETT I N GG
S ET TING GG
S ET TIN GGG
S ET TI NGGG
S ET TI N GG
S ET T INGGG
S ET T IN GG
S ET T I NGG
S ET T I N G
S E TTINGN G
S E TTIN G G
S E TTI NG G
S E TTI N GG
S E TT INGGG
S E TT IN GG
S E TT I NGG
S E TT I N G
S E T TING G
S E T TIN GG
S E T TI NGG
S E T TI N G
S E T T INGG
S E T T IN G
S E T T I NG
S E T T I N G
// Include header file
#include <iostream>
#include<string.h>

using namespace std;
/*
  C++ Program for
  Permutation with spaces 
*/
class Permutations
{
	public:
		// Perform of permutation with include space between characters
		void spacePermutation(string str, char result[], int n, int i, int j)
		{
			if (i == n)
			{
				// Display permutation
				for (int k = 0; k < n *2; ++k)
				{
					cout << result[k];
				}
				// Include new line
				cout << "\n";
				return;
			}
			// Include str element
			result[j] = str[i];
			// Find next permutation Through by recursion
			this->spacePermutation(str, result, n, i + 1, j + 1);
			// Include space
			result[j] = ' ';
			// Include str element
			result[j + 1] = str[i];
			// Find next permutation Through by recursion
			this->spacePermutation(str, result, n, i + 1, j + 2);
		}
	// Handles the request of finding permutation
	void permutation(string str)
	{
		// Get the size
		int n = str.size();
		// This is used to store result
		char result[n *2];
		// Set initial value
		for (int i = 0; i < n *2; ++i)
		{
			if (i < n)
			{
				result[i] = str[i];
			}
			else
			{
				// Append the space character at last
				result[i] = ' ';
			}
		}
		this->spacePermutation(str, result, n, 1, 1);
	}
};
int main()
{
	Permutations task = Permutations();
	string str = "SETTING";
	task.permutation(str);
	return 0;
}

Output

SETTING
SETTIN G
SETTI NG
SETTI N G
SETT INGG
SETT IN G
SETT I NG
SETT I N G
SET TING G
SET TIN GG
SET TI NGG
SET TI N G
SET T INGG
SET T IN G
SET T I NG
SET T I N G
SE TTINGN G
SE TTIN G G
SE TTI NG G
SE TTI N GG
SE TT INGGG
SE TT IN GG
SE TT I NGG
SE TT I N G
SE T TING G
SE T TIN GG
SE T TI NGG
SE T TI N G
SE T T INGG
SE T T IN G
SE T T I NG
SE T T I N G
S ETTING N G
S ETTIN GN G
S ETTI NGN G
S ETTI N G G
S ETT INGG G
S ETT IN G G
S ETT I NG G
S ETT I N GG
S ET TING GG
S ET TIN GGG
S ET TI NGGG
S ET TI N GG
S ET T INGGG
S ET T IN GG
S ET T I NGG
S ET T I N G
S E TTINGN G
S E TTIN G G
S E TTI NG G
S E TTI N GG
S E TT INGGG
S E TT IN GG
S E TT I NGG
S E TT I N G
S E T TING G
S E T TIN GG
S E T TI NGG
S E T TI N G
S E T T INGG
S E T T IN G
S E T T I NG
S E T T I N G
// Include namespace system
using System;
/*
  C# Program for
  Permutation with spaces 
*/
public class Permutations
{
	// Perform of permutation with include space between characters
	public void spacePermutation(String str, char[] result, int n, int i, int j)
	{
		if (i == n)
		{
			// Display permutation
			for (int k = 0; k < n * 2; ++k)
			{
				Console.Write(result[k]);
			}
			// Include new line
			Console.Write("\n");
			return;
		}
		// Include str element
		result[j] = str[i];
		// Find next permutation Through by recursion
		spacePermutation(str, result, n, i + 1, j + 1);
		// Include space
		result[j] = ' ';
		// Include str element
		result[j + 1] = str[i];
		// Find next permutation Through by recursion
		spacePermutation(str, result, n, i + 1, j + 2);
	}
	// Handles the request of finding permutation
	public void permutation(String str)
	{
		// Get the size
		int n = str.Length;
		// This is used to store result
		char[] result = new char[n * 2];
		// Set initial value
		for (int i = 0; i < n * 2; ++i)
		{
			if (i < n)
			{
				result[i] = str[i];
			}
			else
			{
				// Append the space character at last
				result[i] = ' ';
			}
		}
		spacePermutation(str, result, n, 1, 1);
	}
	public static void Main(String[] args)
	{
		Permutations task = new Permutations();
		String str = "SETTING";
		task.permutation(str);
	}
}

Output

SETTING
SETTIN G
SETTI NG
SETTI N G
SETT INGG
SETT IN G
SETT I NG
SETT I N G
SET TING G
SET TIN GG
SET TI NGG
SET TI N G
SET T INGG
SET T IN G
SET T I NG
SET T I N G
SE TTINGN G
SE TTIN G G
SE TTI NG G
SE TTI N GG
SE TT INGGG
SE TT IN GG
SE TT I NGG
SE TT I N G
SE T TING G
SE T TIN GG
SE T TI NGG
SE T TI N G
SE T T INGG
SE T T IN G
SE T T I NG
SE T T I N G
S ETTING N G
S ETTIN GN G
S ETTI NGN G
S ETTI N G G
S ETT INGG G
S ETT IN G G
S ETT I NG G
S ETT I N GG
S ET TING GG
S ET TIN GGG
S ET TI NGGG
S ET TI N GG
S ET T INGGG
S ET T IN GG
S ET T I NGG
S ET T I N G
S E TTINGN G
S E TTIN G G
S E TTI NG G
S E TTI N GG
S E TT INGGG
S E TT IN GG
S E TT I NGG
S E TT I N G
S E T TING G
S E T TIN GG
S E T TI NGG
S E T TI N G
S E T T INGG
S E T T IN G
S E T T I NG
S E T T I N G
<?php
/*
  Php Program for
  Permutation with spaces 
*/
class Permutations
{
	// Perform of permutation with include space between characters
	public	function spacePermutation($str, & $result, $n, $i, $j)
	{
		if ($i == $n)
		{
			// Display permutation
			for ($k = 0; $k < $n * 2; ++$k)
			{
				echo $result[$k];
			}
			// Include new line
			echo "\n";
			return;
		}
		// Include str element
		$result[$j] = $str[$i];
		// Find next permutation Through by recursion
		$this->spacePermutation($str, $result, $n, $i + 1, $j + 1);
		// Include space
		$result[$j] = ' ';
		// Include str element
		$result[$j + 1] = $str[$i];
		// Find next permutation Through by recursion
		$this->spacePermutation($str, $result, $n, $i + 1, $j + 2);
	}
	// Handles the request of finding permutation
	public	function permutation($str)
	{
		// Get the size
		$n = strlen($str);
		// This is used to store result
		$result = array_fill(0, $n * 2, ' ');
		// Set initial value
		for ($i = 0; $i < $n; ++$i)
		{
			if ($i < $n)
			{
				$result[$i] = $str[$i];
			}
		}
		$this->spacePermutation($str, $result, $n, 1, 1);
	}
}

function main()
{
	$task = new Permutations();
	$str = "SETTING";
	$task->permutation($str);
}
main();

Output

SETTING
SETTIN G
SETTI NG
SETTI N G
SETT INGG
SETT IN G
SETT I NG
SETT I N G
SET TING G
SET TIN GG
SET TI NGG
SET TI N G
SET T INGG
SET T IN G
SET T I NG
SET T I N G
SE TTINGN G
SE TTIN G G
SE TTI NG G
SE TTI N GG
SE TT INGGG
SE TT IN GG
SE TT I NGG
SE TT I N G
SE T TING G
SE T TIN GG
SE T TI NGG
SE T TI N G
SE T T INGG
SE T T IN G
SE T T I NG
SE T T I N G
S ETTING N G
S ETTIN GN G
S ETTI NGN G
S ETTI N G G
S ETT INGG G
S ETT IN G G
S ETT I NG G
S ETT I N GG
S ET TING GG
S ET TIN GGG
S ET TI NGGG
S ET TI N GG
S ET T INGGG
S ET T IN GG
S ET T I NGG
S ET T I N G
S E TTINGN G
S E TTIN G G
S E TTI NG G
S E TTI N GG
S E TT INGGG
S E TT IN GG
S E TT I NGG
S E TT I N G
S E T TING G
S E T TIN GG
S E T TI NGG
S E T TI N G
S E T T INGG
S E T T IN G
S E T T I NG
S E T T I N G
/*
  Node Js Program for
  Permutation with spaces 
*/
class Permutations
{
	// Perform of permutation with include space between characters
	spacePermutation(str, result, n, i, j)
	{
		if (i == n)
		{
			// Display permutation
			for (var k = 0; k < n * 2; ++k)
			{
				process.stdout.write(result[k]);
			}
			// Include new line
			process.stdout.write("\n");
			return;
		}
		// Include str element
		result[j] = str[i];
		// Find next permutation Through by recursion
		this.spacePermutation(str, result, n, i + 1, j + 1);
		// Include space
		result[j] = ' ';
		// Include str element
		result[j + 1] = str[i];
		// Find next permutation Through by recursion
		this.spacePermutation(str, result, n, i + 1, j + 2);
	}
	// Handles the request of finding permutation
	permutation(str)
	{
		// Get the size
		var n = str.length;
		// This is used to store result
		var result = Array(n * 2).fill(' ');
		// Set initial value
		for (var i = 0; i < n; ++i)
		{
			if (i < n)
			{
				result[i] = str[i];
			}
		}
		this.spacePermutation(str, result, n, 1, 1);
	}
}

function main()
{
	var task = new Permutations();
	var str = "SETTING";
	task.permutation(str);
}
main();

Output

SETTING
SETTIN G
SETTI NG
SETTI N G
SETT INGG
SETT IN G
SETT I NG
SETT I N G
SET TING G
SET TIN GG
SET TI NGG
SET TI N G
SET T INGG
SET T IN G
SET T I NG
SET T I N G
SE TTINGN G
SE TTIN G G
SE TTI NG G
SE TTI N GG
SE TT INGGG
SE TT IN GG
SE TT I NGG
SE TT I N G
SE T TING G
SE T TIN GG
SE T TI NGG
SE T TI N G
SE T T INGG
SE T T IN G
SE T T I NG
SE T T I N G
S ETTING N G
S ETTIN GN G
S ETTI NGN G
S ETTI N G G
S ETT INGG G
S ETT IN G G
S ETT I NG G
S ETT I N GG
S ET TING GG
S ET TIN GGG
S ET TI NGGG
S ET TI N GG
S ET T INGGG
S ET T IN GG
S ET T I NGG
S ET T I N G
S E TTINGN G
S E TTIN G G
S E TTI NG G
S E TTI N GG
S E TT INGGG
S E TT IN GG
S E TT I NGG
S E TT I N G
S E T TING G
S E T TIN GG
S E T TI NGG
S E T TI N G
S E T T INGG
S E T T IN G
S E T T I NG
S E T T I N G
#   Python 3 Program for
#   Permutation with spaces 

class Permutations :
	#  Perform of permutation with include space between characters
	def spacePermutation(self, str, result, n, i, j) :
		if (i == n) :
			#  Display permutation
			k = 0
			while (k < n * 2) :
				print(result[k], end = "")
				k += 1
			
			#  Include new line
			print(end = "\n")
			return
		
		#  Include str element
		result[j] = str[i]
		#  Find next permutation Through by recursion
		self.spacePermutation(str, result, n, i + 1, j + 1)
		#  Include space
		result[j] = ' '
		#  Include str element
		result[j + 1] = str[i]
		#  Find next permutation Through by recursion
		self.spacePermutation(str, result, n, i + 1, j + 2)
	
	#  Handles the request of finding permutation
	def permutation(self, str) :
		#  Get the size
		n = len(str)
		#  This is used to store result
		result = [ ' '
		] * (n * 2)
		#  Set initial value
		i = 0
		while (i < n) :
			if (i < n) :
				result[i] = str[i]
			i += 1
		self.spacePermutation(str, result, n, 1, 1)
	

def main() :
	task = Permutations()
	str = "SETTING"
	task.permutation(str)

if __name__ == "__main__": main()

Output

SETTING
SETTIN G
SETTI NG
SETTI N G
SETT INGG
SETT IN G
SETT I NG
SETT I N G
SET TING G
SET TIN GG
SET TI NGG
SET TI N G
SET T INGG
SET T IN G
SET T I NG
SET T I N G
SE TTINGN G
SE TTIN G G
SE TTI NG G
SE TTI N GG
SE TT INGGG
SE TT IN GG
SE TT I NGG
SE TT I N G
SE T TING G
SE T TIN GG
SE T TI NGG
SE T TI N G
SE T T INGG
SE T T IN G
SE T T I NG
SE T T I N G
S ETTING N G
S ETTIN GN G
S ETTI NGN G
S ETTI N G G
S ETT INGG G
S ETT IN G G
S ETT I NG G
S ETT I N GG
S ET TING GG
S ET TIN GGG
S ET TI NGGG
S ET TI N GG
S ET T INGGG
S ET T IN GG
S ET T I NGG
S ET T I N G
S E TTINGN G
S E TTIN G G
S E TTI NG G
S E TTI N GG
S E TT INGGG
S E TT IN GG
S E TT I NGG
S E TT I N G
S E T TING G
S E T TIN GG
S E T TI NGG
S E T TI N G
S E T T INGG
S E T T IN G
S E T T I NG
S E T T I N G
#   Ruby Program for
#   Permutation with spaces 

class Permutations 
	#  Perform of permutation with include space between characters
	def spacePermutation(str, result, n, i, j) 
		if (i == n) 
			#  Display permutation
			k = 0
			while (k < n * 2) 
				print(result[k])
				k += 1
			end
			#  Include new line
			print("\n")
			return
		end

		#  Include str element
		result[j] = str[i]
		#  Find next permutation Through by recursion
		self.spacePermutation(str, result, n, i + 1, j + 1)
		#  Include space
		result[j] = ' '
		#  Include str element
		result[j + 1] = str[i]
		#  Find next permutation Through by recursion
		self.spacePermutation(str, result, n, i + 1, j + 2)
	end

	#  Handles the request of finding permutation
	def permutation(str) 
		#  Get the size
		n = str.length()
		#  This is used to store result
		result = Array.new(n * 2) {' '}
		#  Set initial value
		i = 0
		while (i < n) 
			if (i < n) 
				result[i] = str[i]
			end
			i += 1
		end

		self.spacePermutation(str, result, n, 1, 1)
	end

end

def main() 
	task = Permutations.new()
	str = "SETTING"
	task.permutation(str)
end

main()

Output

SETTING       
SETTIN G      
SETTI NG      
SETTI N G     
SETT INGG     
SETT IN G     
SETT I NG     
SETT I N G    
SET TING G    
SET TIN GG    
SET TI NGG    
SET TI N G    
SET T INGG    
SET T IN G    
SET T I NG    
SET T I N G   
SE TTINGN G   
SE TTIN G G   
SE TTI NG G   
SE TTI N GG   
SE TT INGGG   
SE TT IN GG   
SE TT I NGG   
SE TT I N G   
SE T TING G   
SE T TIN GG   
SE T TI NGG   
SE T TI N G   
SE T T INGG   
SE T T IN G   
SE T T I NG   
SE T T I N G  
S ETTING N G  
S ETTIN GN G  
S ETTI NGN G  
S ETTI N G G  
S ETT INGG G  
S ETT IN G G  
S ETT I NG G  
S ETT I N GG  
S ET TING GG  
S ET TIN GGG  
S ET TI NGGG  
S ET TI N GG  
S ET T INGGG  
S ET T IN GG  
S ET T I NGG  
S ET T I N G  
S E TTINGN G  
S E TTIN G G  
S E TTI NG G  
S E TTI N GG  
S E TT INGGG  
S E TT IN GG  
S E TT I NGG  
S E TT I N G  
S E T TING G  
S E T TIN GG  
S E T TI NGG  
S E T TI N G  
S E T T INGG  
S E T T IN G  
S E T T I NG  
S E T T I N G 
/*
  Scala Program for
  Permutation with spaces 
*/
class Permutations
{
	// Perform of permutation with include space between characters
	def spacePermutation(str: String, result: Array[Character], n: Int, i: Int, j: Int): Unit = {
		if (i == n)
		{
			// Display permutation
			var k: Int = 0;
			while (k < n * 2)
			{
				print(result(k));
				k += 1;
			}
			// Include new line
			print("\n");
			return;
		}
		// Include str element
		result(j) = str(i);
		// Find next permutation Through by recursion
		this.spacePermutation(str, result, n, i + 1, j + 1);
		// Include space
		result(j) = ' ';
		// Include str element
		result(j + 1) = str(i);
		// Find next permutation Through by recursion
		this.spacePermutation(str, result, n, i + 1, j + 2);
	}
	// Handles the request of finding permutation
	def permutation(str: String): Unit = {
		// Get the size
		var n: Int = str.length();
		// This is used to store result
		var result: Array[Character] = Array.fill[Character](n * 2)(' ');
		// Set initial value
		var i: Int = 0;
		while (i < n)
		{
			if (i < n)
			{
				result(i) = str(i);
			}
			i += 1;
		}
		this.spacePermutation(str, result, n, 1, 1);
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Permutations = new Permutations();
		var str: String = "SETTING";
		task.permutation(str);
	}
}

Output

SETTING
SETTIN G
SETTI NG
SETTI N G
SETT INGG
SETT IN G
SETT I NG
SETT I N G
SET TING G
SET TIN GG
SET TI NGG
SET TI N G
SET T INGG
SET T IN G
SET T I NG
SET T I N G
SE TTINGN G
SE TTIN G G
SE TTI NG G
SE TTI N GG
SE TT INGGG
SE TT IN GG
SE TT I NGG
SE TT I N G
SE T TING G
SE T TIN GG
SE T TI NGG
SE T TI N G
SE T T INGG
SE T T IN G
SE T T I NG
SE T T I N G
S ETTING N G
S ETTIN GN G
S ETTI NGN G
S ETTI N G G
S ETT INGG G
S ETT IN G G
S ETT I NG G
S ETT I N GG
S ET TING GG
S ET TIN GGG
S ET TI NGGG
S ET TI N GG
S ET T INGGG
S ET T IN GG
S ET T I NGG
S ET T I N G
S E TTINGN G
S E TTIN G G
S E TTI NG G
S E TTI N GG
S E TT INGGG
S E TT IN GG
S E TT I NGG
S E TT I N G
S E T TING G
S E T TIN GG
S E T TI NGG
S E T TI N G
S E T T INGG
S E T T IN G
S E T T I NG
S E T T I N G
/*
  Swift 4 Program for
  Permutation with spaces 
*/
class Permutations
{
	// Perform of permutation with include space between characters
	func spacePermutation( _ str:[Character], _ result: inout[Character], _ n: Int, _ i: Int, _ j: Int)
	{
		if (i == n)
		{
			// Display permutation
			var k: Int = 0;
			while (k < n * 2)
			{
				print(result[k], terminator: "");
				k += 1;
			}
			// Include new line
			print(terminator: "\n");
			return;
		}
		// Include str element
		result[j] = str[i];
		// Find next permutation Through by recursion
		self.spacePermutation(str, &result, n, i + 1, j + 1);
		// Include space
		result[j] = " ";
		// Include str element
		result[j + 1] = str[i];
		// Find next permutation Through by recursion
		self.spacePermutation(str, &result, n, i + 1, j + 2);
	}
	// Handles the request of finding permutation
	func permutation(_ text: String)
	{
		// Get the size
		let n: Int = text.count;
		// This is used to store result
		var result: [Character] = Array(repeating: " ", count: n * 2);
      	let str = Array(text);
		// Set initial value
		var i: Int = 0;
		while (i < n)
		{
			if (i < n)
			{
				result[i] = str[i];
			}
			i += 1;
		}
		self.spacePermutation(str, &result, n, 1, 1);
	}
}
func main()
{
	let task: Permutations = Permutations();
	let str: String = "SETTING";
	task.permutation(str);
}
main();

Output

SETTING
SETTIN G
SETTI NG
SETTI N G
SETT INGG
SETT IN G
SETT I NG
SETT I N G
SET TING G
SET TIN GG
SET TI NGG
SET TI N G
SET T INGG
SET T IN G
SET T I NG
SET T I N G
SE TTINGN G
SE TTIN G G
SE TTI NG G
SE TTI N GG
SE TT INGGG
SE TT IN GG
SE TT I NGG
SE TT I N G
SE T TING G
SE T TIN GG
SE T TI NGG
SE T TI N G
SE T T INGG
SE T T IN G
SE T T I NG
SE T T I N G
S ETTING N G
S ETTIN GN G
S ETTI NGN G
S ETTI N G G
S ETT INGG G
S ETT IN G G
S ETT I NG G
S ETT I N GG
S ET TING GG
S ET TIN GGG
S ET TI NGGG
S ET TI N GG
S ET T INGGG
S ET T IN GG
S ET T I NGG
S ET T I N G
S E TTINGN G
S E TTIN G G
S E TTI NG G
S E TTI N GG
S E TT INGGG
S E TT IN GG
S E TT I NGG
S E TT I N G
S E T TING G
S E T TIN GG
S E T TI NGG
S E T TI N G
S E T T INGG
S E T T IN G
S E T T I NG
S E T T I N G
/*
  Kotlin Program for
  Permutation with spaces 
*/
class Permutations
{
	// Perform of permutation with include space between characters
	fun spacePermutation(str: String, result: Array<Char> , n: Int, i: Int, j: Int): Unit
	{
		if (i == n)
		{
			// Display permutation
			var k: Int = 0;
			while (k < n * 2)
			{
				print(result[k]);
				k += 1;
			}
			// Include new line
			print("\n");
			return;
		}
		// Include str element
		result[j] = str[i];
		// Find next permutation Through by recursion
		this.spacePermutation(str, result, n, i + 1, j + 1);
		// Include space
		result[j] = ' ';
		// Include str element
		result[j + 1] = str[i];
		// Find next permutation Through by recursion
		this.spacePermutation(str, result, n, i + 1, j + 2);
	}
	// Handles the request of finding permutation
	fun permutation(str: String): Unit
	{
		// Get the size
		var n: Int = str.count();
		// This is used to store result
		var result: Array<Char> = Array(n * 2){' '};
		// Set initial value
		var i: Int = 0;
		while (i < n)
		{
			if (i < n)
			{
				result[i] = str[i];
			}
			i += 1;
		}
		this.spacePermutation(str, result, n, 1, 1);
	}
}
fun main(args: Array<String> ): Unit
{
	var task: Permutations = Permutations();
	var str: String = "SETTING";
	task.permutation(str);
}

Output

SETTING
SETTIN G
SETTI NG
SETTI N G
SETT INGG
SETT IN G
SETT I NG
SETT I N G
SET TING G
SET TIN GG
SET TI NGG
SET TI N G
SET T INGG
SET T IN G
SET T I NG
SET T I N G
SE TTINGN G
SE TTIN G G
SE TTI NG G
SE TTI N GG
SE TT INGGG
SE TT IN GG
SE TT I NGG
SE TT I N G
SE T TING G
SE T TIN GG
SE T TI NGG
SE T TI N G
SE T T INGG
SE T T IN G
SE T T I NG
SE T T I N G
S ETTING N G
S ETTIN GN G
S ETTI NGN G
S ETTI N G G
S ETT INGG G
S ETT IN G G
S ETT I NG G
S ETT I N GG
S ET TING GG
S ET TIN GGG
S ET TI NGGG
S ET TI N GG
S ET T INGGG
S ET T IN GG
S ET T I NGG
S ET T I N G
S E TTINGN G
S E TTIN G G
S E TTI NG G
S E TTI N GG
S E TT INGGG
S E TT IN GG
S E TT I NGG
S E TT I N G
S E T TING G
S E T TIN GG
S E T TI NGG
S E T TI N G
S E T T INGG
S E T T IN G
S E T T I NG
S E T T I N G


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved