数组的操作处理与数组元素的冒泡排序

//(1)查找数组元素

static void Main(string[] args)
{
// TODO: 查找数组元素
int[] a= new int[100];
Console.WriteLine("输入数字");
string s=Console.ReadLine();

int x=Int32.Parse(s);
Console.WriteLine("\n 输入int数组元素 \n");

for(int i=0;i

 1<x;i++) ();="" (2)查找数组元素中最大和最小的元素="" \---------------------------------------="" a="new" a[i]="Int32.Parse(s1);" args)="" at="" console.readline="" console.writeline("element="" console.writeline("search="" console.writeline("搜查元素\n");="" console.writeline("输入int数组大小");="" console.writeline("输入数组元素");="" float="" for(int="" found="" i="1;i&lt;n;i++)" if(a[i]="" int="" int[50];="" int[]="" large="a[0];" large,small;="" location="" main(string[]="" n="Int32.Parse(s);" n;="" return;="" s="Console.ReadLine();" s1="Console.ReadLine();" s3="Console.ReadLine();" small="a[0];" static="" string="" successful");="" todo:="" void="" x2="Int32.Parse(s3);" {="" {0}="" {1}\n",x2,i+1);="" }="" 循环部分数组="" 找出最大和最小的元素="">large)   
 2large=a[i]; //更新large变量   
 3else if(a[i]<small) ();="" *="" \----------------------------------------------="" a="new" a[j]="Int32.Parse(s1);" args)="" array="" console.readline="" console.writeline("largest="" console.writeline("smallest="" console.writeline("输入int数组里的元素数目");="" console.writeline("输入元素");="" element="" for(int="" if(a[j]="" in="" int="" int[100];="" int[]="" is="" j="0;j&lt;limit-pass;j++)" limit="x-1;" main(string[]="" pass="0;pass&lt;x-1;pass++)" s="Console.ReadLine();" s1="Console.ReadLine();" small="a[i];" static="" string="" the="" void="" x="Int32.Parse(s);" {="" {0}",large);="" {0}",small);="" }="" 数组元素的冒泡排序="" 暂停="" 更新small变量="" 第一遍使最轻的记录上升到数组的最顶端,="" 第二遍使剩下的最小的上升到第二位置,="" 第二遍扫描时不必再比较最顶端的记录="">a[j+1])   
 4{   
 5int k=a[j]; //数组元素交换   
 6a[j]=a[j+1]; //数组元素交换   
 7a[j+1]=k; //数组元素交换   
 8}   
 9}   
10} 
11
12Console.WriteLine("Sorted elements of an array are(冒泡排序)"); 
13
14for (int j=0;j&lt;x;j++)   
15{   
16Console.WriteLine(a[j]);   
17}   
18Console.ReadLine ();   
19} 
20
21\---------------------------------------</small)></x;i++)>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus