123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- namespace AtlasUtility
- {
- using System;
- using System.Collections.Generic;
- public static class ExtList
- {
- public static T Back<T>(this List<T> list, int index, bool remove = false)
- {
- T t = list[list.Count - 1 - index];
- if (remove)
- {
- list.RemoveAt(list.Count - 1 - index);
- }
- return t;
- }
- public static void RemoveRange<T>(this List<T> list, List<T> targetList)
- {
- foreach (var t in targetList)
- {
- list.Remove(t);
- }
- }
- public static void MySort<T>(this List<T> list, Func<T, T, bool> compare)
- {
- for (int i = 0; i < list.Count; i++)
- {
- bool finish = true;
- for (int j = 0; j < list.Count - i - 1; j++)
- {
- if (compare(list[j], list[j + 1]))
- {
- finish = false;
- T t = list[j];
- list[j] = list[j + 1];
- list[j + 1] = t;
- }
- }
- if (finish)
- {
- break;
- }
- }
- }
- public static float MyMax<T>(this List<T> list, Func<T, float> calculate)
- {
- float result = calculate(list[0]);
- for (int i = 1; i < list.Count; i++)
- {
- if (result < calculate(list[i]))
- {
- result = calculate(list[i]);
- }
- }
- return result;
- }
- public static float MySum<T>(this List<T> list, Func<T, float> calculate)
- {
- float result = 0;
- for (int i = 0; i < list.Count; i++)
- {
- result += calculate(list[i]);
- }
- return result;
- }
- }
- }
|