Array declaration and assignment: int[] a=new int[6];
Array initializer: int[] a=new int[2]{1,3};
Array initializer simplified version: int[] a={1,3};
Array Initial value: Number type: 0
Bool:false
Char:
String:null
Suppose there is an array of nums, with a length of 5, to sort it in ascending order
Array length: A. Length;
Array sorting:
First, Exchange sort
Sorting ideas:
- In the range of subscript 0-4, the smallest number in the range is referred to subscript 0
- In the range of subscript 1-4, the smallest number in the range is referred to subscript 1
- In the range of subscript 2-4, the smallest number in the range is referred to subscript 2
- In the range of subscript 3-4, the smallest number in the range is referred to subscript 3
- Sort done!
Implementation code:
for(inti =0; I < Nums. Length-1; i++){ //in the I-(nums. LENGTH-1) within the range, the smallest number in the range is referred to I for(intj = i +1; J < Nums. Length; J + +) { if(Nums[i] >Nums[j]) { //Exchange inttemp =Nums[i]; Nums[i]=Nums[j]; NUMS[J]=temp; } }}
Second, bubble sort
Sorting ideas:
- Sink the largest number to the bottom
Or
- Take the smallest number to the top
Implementation code:
for(inti = Nums. Length-1; i >0; i--){ //within the range of 0-i, the largest number in the range is sunk to I for(intj =0; J < I; J + +) { if(Nums[j] > nums[j+1]) { //Exchange inttemp =Nums[j]; NUMS[J]= nums[j+1]; Nums[j+1] =temp; } }}
C # Array Brief