#region 随机链表
void GetRandomList<T>(ref List<T> list)
{
int i, r = list.Count - 1;
System.Random rand = new System.Random();
for (i = 0; i < list.Count; i++)
{
int n = rand.Next(0, r);
T tem = list[i];
list[i] = list[n];
list[n] = tem;
r--;
}
}
//随机数组
void GetRandomArray<T>(T[] arr)
{
int i, r = arr.Length - 1;
System.Random rand = new System.Random();
for (i = 0; i < arr.Length; i++)
{
int n = rand.Next(0, r);
T tem = arr[i];
arr[i] = arr[n];
arr[n] = tem;
r--;
}
}
#endregion
随机链表
最新推荐文章于 2023-02-18 17:56:14 发布