当前位置:网站首页>One dimensional array two dimensional array (sort Max insert sort)
One dimensional array two dimensional array (sort Max insert sort)
2022-07-03 08:05:00 【Luckyᕙ(⇀‸↼‵‵)ᕗ】
One . One dimensional array
1. Definition
3W:why what when
1H:how
Why: Solve the problem of mass data calculation
Yes 10 Ten thousand variables : among 3 All integers ,4 10000 double precision ,2 Ten thousand strings ,1 Ten thousand objects
An array of integers :3 All integers
Double precision array :4 10000 double precision
Array of strings :2 Ten thousand strings
An array of objects :1 Ten thousand objects
What: Definition
The dynamic array ( Show array ): data type [] Variable name =new data type [ size ];
int[] a=new int[30000];
2、 visit
Array access :a[i] i: Subscript ( from 0 Start )
assignment :a[0]=1;
void Get()
{
int[] a = newint[5];// Define a have 5 Integer value of elements
a[0] = 1;
a[1] = 2;
a[2] = 3;
a[3] = 4;
a[4] = 5;
Console.WriteLine(a[0] + "\t" + a[3]);
}
void Get2()
{
int[] a = newint[5];
//for (int i = 0; i <5; i++)
//for (int i = 0; i <= 4; i++)
for (int i = 0; i <a.Length; i++)//a.Length: Length of array
{
a[i] = i + 1;
}
Console.WriteLine(a[0] + "\t" + a[3]);
// Unhandled exception : System.IndexOutOfRangeException: Index out of array bounds .
}
staticvoid Main(string[] args)
{
Test15 t = newTest15();
t.Get2();
}
Static array ( Implicit array )
int[] x={1,2,3,4,5};
void Get3()
{
// hold a Put the values of the array in reverse order b Array
int[] a = { 1, 2, 3, 4, 5 };
int[] b = newint[5];
for (int i = a.Length-1; i >= 0; i--)// Loop assignment
{
b[4-i = a[i];//i:4 3 2 1 0
}
for (int i = 0; i < b.Length; i++)// Cyclic output
{
Console.WriteLine(b[i]);
}
}
Two . Two dimensional array
1. Definition
int[,] ABC = new int[3, 4] { { 4,5,8,7}, { 4, 5, 8, 7 }, { 4, 5, 8, 7},};
public enum AerType { // enumeration
hj,
bjhg,
hja = 8,
}
static void Main(string[] args) {
switch (AerType.bjhg) {
case AerType.hj:
break;
case AerType.bjhg:
break;
case AerType.hja:
break;
default:
break;
} }
3、 ... and . Sort
Array.Sort()
// Arrange the data in positive order
int[] a = { 95, 74, 63, 87, 55 };
Array.Sort(a);
for (int i = 0; i < a.Length; i++) { Console.WriteLine(a[i]); }
// Arrange the data in reverse order
for (int i = a.Length-1; i >=0 ; i--) { Console.WriteLine(a[i]); }
void Get5()
{
// Bubble sort
int[] a = { 95, 74, 63, 87, 55 };
int t;
for (int i = 0; i < a.Length; i++) {
for (int j = i; j < a.Length; j++) {
if (a[i] > a[j])// From small to large {
t = a[i];
a[i] = a[j];
a[j] = t;
}
}
}
for (int i = 0; i < a.Length; i++) { Console.WriteLine(a[i]); }
}
4、 For maximum
void Get6()
{
// Get the highest score
int[] a = { 45, 74, 63, 87, 55 };
//1、 Suppose a number in the array is the highest score
int max = a[2];
//2、 Circular array , Find out the ratio max Big points , Assign this score to max
for (int i = 0; i < a.Length; i++) { if (a[i] > max) { max = a[i]; } }
Console.WriteLine(max);
}
5、 ... and . Insertion sort
There is a group of students' achievements {99,85,82,63, 60}, To increase the performance of a student , Insert it into the grade sequence , And keep descending
65
analysis :
- Find a number smaller than this data for the first time , This number is where the data is to be inserted i( Judge this data ), Exit the loop when found
- from i Position of backward , Move the following data backward in turn
- hold i This position is assigned to the data to be inserted
void Insert()// Insertion sort
{
int[] a = { 99, 85, 82, 63, 60,0 };
int b=65,index=0;
for (int i = 0; i < a.Length; i++) {
if (b >= a[i]) { index = i; break; }
}
//99,85,82,63, 60 []
//99,85,82,[i] ,63, 60
//99,85,82,[index] ,63(i), 60
for (int i = a.Length - 1; i >= index + 1; i--) { a[i] = a[i - 1]; }
a[index] = b;
for (int i = 0; i < a.Length; i++) { Console.WriteLine(a[i]); }
}
边栏推荐
- the installer has encountered an unexpected error installing this package
- [at] ABC 258g - triple Reach - violence
- Differences between tp3.2 and tp5.0
- P2622 关灯问题II(状态压缩 搜索)
- Uniapp learning records
- P2622 light off problem II (state compression search)
- 方正锐利重磅升级到12.0版本,包装印前处理更加便捷、高效!
- 一个实习生的CnosDB之旅
- 多旅行商问题——公式和求解过程概述
- Ventuz Foundation Series "one step at the door"
猜你喜欢
![[MySQL 14] use dbeaver tool to remotely backup and restore MySQL database (Linux Environment)](/img/38/3435d353e50b19fe09c8ab9db52204.png)
[MySQL 14] use dbeaver tool to remotely backup and restore MySQL database (Linux Environment)
![[cocos creator] Click the button to switch the interface](/img/b8/f0fd54a2a197cbfd788990e2806b52.png)
[cocos creator] Click the button to switch the interface

Editor Extensions

超限黑客认知

haproxy+keepalived集群搭建02

多旅行商问题——公式和求解过程概述
![[MySQL 12] MySQL 8.0.18 reinitialization](/img/e1/9874df18bbc8d80c3c5c5fe39aefc9.png)
[MySQL 12] MySQL 8.0.18 reinitialization

An intern's journey to cnosdb

Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does

How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
随机推荐
Technical dry goods | thinking about the unification of dynamic and static diagrams of AI framework
【cocos creator】获取资源uuid
What is a data type? What is the use of data types?
oracle中的 (+)是什么意思
Wechat native applet cloud development learning record 01
P2622 light off problem II (state compression search)
Huawei switches are configured with SSH login remote management switches
Youyou1 of xlua knapsack system
L'installateur a été installé avec une erreur inattendue
LwIP learning socket (API)
[global product discovery 2] the first pure cloud augmented reality (AR) platform - Israel
MAE
Lua framwrok framework starts
Multi traveling salesman problem -- overview of formula and solution process
I want to do large screen data visualization application feature analysis
Lua hot update basic grammar
Storage of data
Install cross compiler arm none liunx gnueabihf
Screenshot tool snipaste
the installer has encountered an unexpected error installing this package