对数组元素进行整理将一个整型数组调整为这样的数组:所有3的倍数在最左边,所有除以3余1的数在中间,而所有除以3余2的数放在最右边,元素的前后位置仍为原来的顺次。★C#控制台代码如下:usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.IO;namespaceGetWordContent{classProgram{[STAThread]staticvoidMain(string[]args){int[]a=newint[]{25,8,36,45,37,39,38,1,2,43,7,10,14,21,23,24,87,85,83};Console.WriteLine(未整理数组前的数组内容:);PrintArrayInfo(a);//除y以°?3的Ì?在¨²最Á?左Á¨®边À?除y以°?3余®¨¤1在¨²中D间?余®¨¤2的Ì?在¨²最Á?后¨®for(inti=0;ia.Length;i++){if(a[i]%3!=0){for(intj=i+1;ja.Length;j++){if(a[j]%3==0){inttemp=a[j];for(intk=j;ki;k--){a[k]=a[k-1];//25,8,36变成36,25,8}a[i]=temp;break;}}}}Console.WriteLine(能¨¹被À?3整?除y的Ì?数ºy放¤?在¨²数ºy组Á¨¦的Ì?最Á?左Á¨®边À?:êo);PrintArrayInfo(a);//获?得Ì?不?能¨¹被À?3整?除y的Ì?元a素?的Ì?起e始º?索¡Â引°yintnotFirstIndex=0;for(inti=0;ia.Length;i++){if(a[i]%3!=0){notFirstIndex=i;break;}}Console.WriteLine(此ä?时º¡À不?能¨¹被À?3的Ì?整?除y的Ì?第̨²一°?个?元a素?的Ì?索¡Â引°y是º?:êo{0},notFirstIndex);Console.WriteLine(将?从䨮索¡Â引°y[{0}]开a始º?进?行D(除y以°?3余®¨¤1)的Ì?元a素?的Ì?整?理¤¨ª,notFirstIndex);/*for(inti=notFirstIndex;ia.Length;i++){if(a[i]%3!=1){for(intj=i+1;ja.Length;j++){if(a[j]%3==1){inttemp=a[j];for(intk=j;ki;k--){a[k]=a[k-1];}a[i]=temp;break;}}}}*///该?调Ì¡Â用®?函¡¥数ºy也°2可¨¦以°?用®?上¦?面?注Á¡é释º¨ª的Ì?一°?段?代䨲替¬?ArrangeArray(a,1,notFirstIndex);PrintArrayInfo(a);Console.WriteLine(剩º¡ê余®¨¤的Ì?最Á?后¨®的Ì?元a素?一°?定¡§是º?(除y以°?3余®¨¤2)的Ì?元a素?,ê?因°¨°此ä?不?用®?再¨´次ä?整?理¤¨ª);Console.ReadLine();}///summary///打印数组////summary///paramname=a/paramprivatestaticvoidPrintArrayInfo(int[]a){if(a==null)Console.WriteLine();StringBuildersb=newStringBuilder({);for(inti=0;ia.Length;i++){sb.AppendFormat({0}{1},i==0?:,,a[i]);}sb.Append(});Console.WriteLine(sb.ToString());}///summary///对数组进行整理////summary///paramname=a/param///paramname=remainder余数/param///paramname=firstIndex起始索引/paramprivatestaticvoidArrangeArray(int[]a,intremainder,intfirstIndex){for(inti=firstIndex;ia.Length;i++){if(a[i]%3!=remainder){for(intj=i+1;ja.Length;j++){if(a[j]%3==remainder){inttemp=a[j];for(intk=j;ki;k--){a[k]=a[k-1];}a[i]=temp;break;}}}}}}}★程序运行后截图: