当前位置:网站首页>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]); }
}
边栏推荐
- E: 无法定位软件包 ros-melodic-desktop-full
- jsutlis
- [set theory] order relation (the relation between elements of partial order set | comparable | strictly less than | covering | Haas diagram)
- My touch screen production "brief history" 2
- 什么是数据类型?数据类型有什么用?
- [step on the pit series] MySQL failed to modify the root password
- Oracle queries grouped by time
- 2020-12-12
- P1896 [scoi2005] non aggression (shape pressure DP)
- Idea dereference display effect
猜你喜欢

Zohocrm deluge function application time verification

My touch screen production "brief history" 2

My touch screen production "brief history" 1

Viz artist advanced script video tutorial -- stringmap use and vertex operation

I want to do large screen data visualization application feature analysis

*p++、*++p、++*p、(*p)++

What to do after the browser enters the URL

Unity XR realizes interaction (grasping, moving, rotating, transmitting, shooting) -pico

Install cross compiler arm none liunx gnueabihf

oracle 插入单引号
随机推荐
Technical dry goods Shengsi mindspire dynamic transformer with variable sequence length has been released!
Wechat applet taro learning record
Microsoft Security Response Center
Idea dereference display effect
[at] ABC 258g - Triangle triples reachable - violence
数据库应用技术课程设计之商城管理系统
Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
Use filechannel to copy files
璞华PLM为全场景产品生命周期管理赋能,助力产品主线的企业数字化转型
Ventuz Foundation Series "one step at the door"
PHP wechat red packet grabbing algorithm
static关键字
Usage of (case, when) in PostgreSQL
Product creation and commercial realization of chat robot (according to La Ma Bang - Dr. Wang Jingjing - speech)
How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
[at] abc 258G - Triangle 三元组可达-暴力
MAE
链式长取值
PHP common sorting algorithm
JS to implement publish and subscribe