using UnityEngine;
namespace QuickSort
{
public class TestQuickSort : MonoBehaviour
{
private void Awake()
{
int[] testArray =new int[100] ;
for (int i = 0; i < testArray.Length; i++)
{
testArray[i] = Random.Range(0,200);
}
QuickSort(testArray,0, testArray.Length-1);
string str = "";
for (int i = 0; i < testArray.Length; i++)
{
str+= testArray[i] + " ";
}
Debug.Log(str);
Debug.Log(TwoPartsSearch(100, testArray,0, testArray.Length));//有序数组
}
//快速排序
private void QuickSort(int[] _array,int _left,int _right) {
if (_left>=_right) {
return;
}
int leftIndex =_left;
int rightIndex = _right;
int midIndex = _le
unity 使用快速排序、二分法查找
最新推荐文章于 2024-05-21 23:56:53 发布