当前位置:网站首页>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
- Ventuz Foundation Series "one step at the door"
- Client server model
- Storage of data
- MAE
- the installer has encountered an unexpected error installing this package
- PIP uses image website to solve the problem of slow network speed
- Are you still watching the weather forecast on TV?
- Demonstration of plug-in use of ventuz basic series
- Technical dry goods | thinking about the unification of dynamic and static diagrams of AI framework
猜你喜欢

My touch screen production "brief history" 2

Iterm2 setting

unity2019_ Input management

Multi traveling salesman problem -- overview of formula and solution process

Shader foundation 01
![[set theory] order relation (hastu example | divisive relation hastu | inclusive relation hastu | refinement relation hastu)](/img/de/1c75b5e7ed79aca47462de365428a7.jpg)
[set theory] order relation (hastu example | divisive relation hastu | inclusive relation hastu | refinement relation hastu)

C language learning notes (mind map)

一个实习生的CnosDB之旅

【cocos creator】点击按钮切换界面

Unity2019_ Natural ambient light_ Sky box
随机推荐
PIP uses image website to solve the problem of slow network speed
How to establish rectangular coordinate system in space
WPF:解决MaterialDesign:DialogHost 无法关闭问题
Viz artist advanced script video tutorial -- stringmap use and vertex operation
RM delete file
Unity2019_ Lighting system
Idea unreference Display Effect
E: Unable to locate package ROS melody desktop full
Huawei s5700 switch initialization and configuration SSH and telnet remote login methods
2020-12-12
MAE
Static keyword
Luaframwrok handles resource updates
P2622 light off problem II (state compression search)
Ventuz Foundation Series "one step at the door"
regular expression
What to do after the browser enters the URL
[MySQL 11] how to solve the case sensitive problem of MySQL 8.0.18
oracle 插入单引号
Install cross compiler arm none liunx gnueabihf