Example: Enter the student's data, then reorder according to the student's score. Review the structure, collection, array, for loop, bubble sort, and the use of the horizontal character.

Source: Internet
Author: User

Class Program

{

struct Student//define a student structure

{

public string name; Basic format

public int code;

public int age;

public int Fenshu;

}

static void Main (string[] args)

{

while (true)

{

ArrayList al = new ArrayList (); To define a new collection

Console.Write ("Please enter the number of people:");

int Renshu = Convert.ToInt32 (Console. ReadLine ());

for (int i = 0; i < Renshu; i++)

{

Student R = new Student (); Defines a variable of type R student, which can store numeric values

Console.Write ("Please enter student's name:");

R.name = Console.ReadLine ();

Console.Write ("Please enter student number:");

R.code = Convert.ToInt32 (Console.ReadLine ());

Console.Write ("Please enter Student Age:");

R.age = Convert.ToInt32 (Console.ReadLine ());

Console.Write ("Please enter student score:");

R.fenshu = Convert.ToInt32 (Console.ReadLine ());

Al.     ADD (R); Put the value of R into the set of al.

}

for (int i = 0; i < Renshu; i++)//Sort by fractional bubble

{

for (int j = i; J < Renshu-1; J + +)

{

if (((student) al[i]) .fenshu< ((student) al[j+1]). Fenshu)//Take a good look at this code, not good understanding, student type in the value from AL

{

Student Zhong;

Zhong = (student) al[i];

Al[i] = al[j + 1];

Al[j + 1] = Zhong;

}

}

}

Console.WriteLine ("Post-row student order");

for (int i = 0; i < Renshu; i++)

{//Horizontal character output

Console.WriteLine ("Name" + ((student) al[i]). name+ "T-number" + ((student) al[i]). Code + "\ t fraction" + ((student) al[i]). Fenshu + "\ t age "+ ((student) al[i]). Age);

}

}

Console.ReadLine ();

Example: Enter the student's data, then reorder according to the student's score. Review the structure, collection, array, for loop, bubble sort, and the use of the horizontal character.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.