using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataStructureExam
{
public class StrPre
{
public static void Main()
{
String str = "xyz";
int n = str.Length;
permute(str, 0, n - 1);
Console.ReadLine();
}
public static void permute(string str, int first, int last)
{
if (first == last)
{
Console.WriteLine(str);
}
else
{
for (int i = first; i <= last; i++)
{
char temp;
char[] charArray =
str.ToCharArray();
temp = charArray[first];
charArray[first] =
charArray[i];
charArray[i] = temp;
string str1 = new string(charArray);
permute(str1, first + 1,
last);
}
}
}
}
}
Output:
No comments:
Post a Comment