标签:style blog color ar for sp div art log
class SortClass: NSObject { func quickSort(inout array:[Int]){ self.quick(&array, left: 0, right: array.count-1) } func quickMain(inout array:[Int],var left:Int,var right:Int)->Int{ var srcLeft=array[left] while(left<right){ while(left<right&&array[right]>=srcLeft){ right-- } array[left]=array[right] while(left<right&&array[left]<=srcLeft){ left++ } array[right]=array[left] } array[left]=srcLeft return left } func quick(inout array:[Int],var left:Int,var right:Int){ if(left<right){ var middle=self.quickMain(&array, left: left, right: right) self.quick(&array, left: left, right: middle-1) self.quick(&array, left: middle+1, right: right) } } func mergerSort(inout array:[Int]){ var tempArray=[Int](count: array.count, repeatedValue: 1) self.merger(&array, tempArray: &tempArray, left: 0, right: array.count-1) } func merger(inout array:[Int],inout tempArray:[Int],var left:Int,var right:Int){ if(left<right){ var middle=(left+right)/2 self.merger(&array, tempArray: &tempArray, left: left, right: middle) self.merger(&array, tempArray: &tempArray, left: middle+1, right: right) self.mergerMain(&array, tempArray: &tempArray, leftStart: left, leftEnd: middle, rightStart: middle+1, rightEnd: right) } } func mergerMain(inout array:[Int],inout tempArray:[Int],var leftStart:Int,var leftEnd:Int,var rightStart:Int,var rightEnd:Int){ var index=leftStart var recoderLeftStart=leftStart; while(leftStart<=leftEnd&&rightStart<=rightEnd){ if(array[leftStart]<=array[rightStart]){ tempArray[index++]=array[leftStart++] }else{ tempArray[index++]=array[rightStart++] } } while(leftStart<=leftEnd){ tempArray[index++]=array[leftStart++] } while(rightStart<=rightEnd){ tempArray[index++]=array[rightStart++] } for(var i=recoderLeftStart;i<=rightEnd;i++){ array[i]=tempArray[i] } } }
学习了swift总体感觉不错.吐嘈两点,1编码的时候智能提示不友好,2希望后续版本能有方法访问权限修饰关键字添加。
标签:style blog color ar for sp div art log
原文地址:http://www.cnblogs.com/learnWindowsPhone/p/4064552.html