1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | def YoyoSort(List): Min = min(List) Max = max(List) Dict = {} for x in List: if Dict.get(x) == None: Dict[x] = 1 else: Dict[x] += 1 New = [] for x in range(Min, Max+1): if Dict.get(x) != None: New.extend([ x for _ in range(Dict[x]) ]) return New | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | private static void YoyoSort(int[] OriginalArray, int Length) { int Min = int.MaxValue; for (int i = 0; i < Length; i++) { if (OriginalArray[i] < Min) { Min = OriginalArray[i]; } } int Max = 0; for (int i = 0; i < Length; i++) { if (OriginalArray[i] > Max) { Max = OriginalArray[i]; } } Dictionary<int, int> CountDict = new Dictionary<int, int>(); for (int i = 0; i < Length; i++) { if (CountDict.ContainsKey(OriginalArray[i]) == false) { CountDict.Add(OriginalArray[i], 1); } else { CountDict[OriginalArray[i]]++; } } int Index = 0; for(int i = Min; i < Max + 1; i++) { if (CountDict.ContainsKey(i) == true) { for(int x = 0; x < CountDict[i]; x++) { OriginalArray[Index] = i; Index++; } } } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | def DedupingSticker(List): Dict={} for x in List: if Dict.get(x) == None: Dict[x] = 1 else: Dict[x] += 1 List = list(Dict.keys()) # List = QuickSort(List) # 아무 정렬이나 가능. 단, List 가 정렬되어야 함 New = [] for x in List: New.extend([ x for _ in range(Dict[x]) ]) return New | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | private static void DedupingSticker(int[] OriginalArray, int Length) { Dictionary<int, int> CountDict = new Dictionary<int, int>(); for (int i = 0; i < Length; i++) { if (CountDict.ContainsKey(OriginalArray[i]) == false) { CountDict.Add(OriginalArray[i], 1); } else { CountDict[OriginalArray[i]]++; } } int[] SortedValue = new int[CountDict.Count]; int SortedValueLen = CountDict.Count; int z = 0; foreach(var Entry in CountDict) { SortedValue[z] = Entry.Key; z++; } //QuickSort(SortedValue, 0, SortedValueLen - 1); //원하는 정렬 아무거나, 단 SortedValue 가 변경되어야 함. for(int i = 0; i < SortedValueLen; i++) { OriginalArray[Length - SortedValueLen + i] = SortedValue[i]; } int Index = 0; for(int i = 0; i < SortedValueLen; i++) { for(int x = 0; x < CountDict[OriginalArray[Length - SortedValueLen + i]]; x++) { OriginalArray[Index] = OriginalArray[Length - SortedValueLen + i]; Index++; } } } | cs |