求代码,求思路!

*将1,2,3,4, .....,99,100的已排序数列,排序成 100,1,99,2,98,3,......,51,50这样的数列。

 

注:数列只是已排序但并不等差,例如:3,5,8,19,21,77,105 ....... 301,302,331,444

 

要求:空间复杂度o(1),时间复杂度o(n)。

用c#语言


郎朗坤
浏览 583回答 1
1回答

慕的地10843

static void Main(string[] args) &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int[] a = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int[] b = new int[10]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int j = 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int i = 0; i < a.Length; i++) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (i % 2 == 0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b[i] = a[a.Length-j-1]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b[i] = a[j++]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp;}
打开App,查看更多内容
随时随地看视频慕课网APP