C#
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace ConsoleApplication4 7 { 8 class Program 9 { 10 static void Main(string[] args) 11 { 12 List<int> originalList = new List<int>(); 13 for (int i = 1; i <= 5; i++) 14 { 15 originalList.Add(i); 16 } 17 Console.Write("源数组:"); 18 foreach (int item in originalList) 19 { 20 Console.Write(item + " "); 21 } 22 Console.WriteLine(); 23 List<List<int>> resultList = new List<List<int>>(); 24 // 每一次由底至上地上升 25 for (int i = 0; i < originalList.Count; i++) 26 { 27 List<int> subList = new List<int>(); 28 for (int j = 0; j < originalList.Count; j++) 29 { 30 if (j != i) 31 { 32 subList.Add(originalList[j]); 33 } 34 } 35 resultList.Add(subList); 36 } 37 for (int i = 0; i < resultList.Count; i++) 38 { 39 List<int> subList = resultList[i]; 40 Console.Write("子数组" + (i + 1) + ":"); 41 for (int j = 0; j < subList.Count; j++) 42 { 43 Console.Write(subList[j] + " "); 44 } 45 Console.WriteLine(); 46 } 47 Console.WriteLine("子数组的数量:" + resultList.Count); 48 Console.ReadKey(); 49 } 50 } 51 }