Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Permutations
- {
- class Program
- {
- static int[] arr = new int[] { 1, 2, 3, 4 };
- static void Main(string[] args)
- {
- Perms(arr.ToList());
- }
- public static void Perms<T>(List<T> list)
- {
- PermsRecursive(new List<T>(), list);
- }
- private static void PermsRecursive<T>(List<T> perm, List<T> list)
- {
- if (list.Count == 0)
- {
- Print(perm);
- }
- else
- foreach (var p in list)
- {
- perm.Add(p);
- List<T> temp = new List<T>(list);
- temp.Remove(p);
- PermsRecursive(perm, temp);
- perm.Remove(perm.Last());
- }
- }
- private static void Print<T>(IEnumerable<T> arr)
- {
- foreach (var a in arr)
- {
- Console.Write(a.ToString());
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment