Untiy-->C# 氣泡排序與不用第三個變數實現排序
阿新 • • 發佈:2019-01-28
using UnityEngine; using System.Collections; public class pppp : MonoBehaviour { public int[] a = {2,3,1,4,6,7,8,9,0}; // Use this for initialization void Start () { for(int j=0;j<a.Length;j++){ for(int i=0;i<a.Length-1;i++){ if(a[i]<a[i+1]){ // int n=a[i]; // a[i]=a[i+1]; // a[i+1]=n; a[i]=a[i]+a[i+1]; a[i+1]=a[i]-a[i+1]; a[i]=a[i]-a[i+1]; } } } foreach(int n in a){ Debug.Log(n); } } // Update is called once per frame void Update () { } }