从文件中排序信息 [英] sorting infos from a file

查看:77
本文介绍了从文件中排序信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能根据学生的姓氏和身份证号从StudentList.txt之类的文本文件中对学生列表进行排序.ypu可以帮助我吗?

how can ı sort a student list from a text file like StudentList.txt according to students'' surname and id number.can ypu help me?

推荐答案

以这种方式执行.使用文件I/O Strems读取文件,然后在screan上显示学生信息时,对其进行排序.为此,您需要将文件读取为两个字符串变量,为此,您必须使用read该方法仅读取直到出现空格或行尾,然后在for循环或while循环中读取文件,然后将第一行保存到第一个变量中,将第二行保存到第二个变量中.使用stringcompartion方法比较这些值,然后以排序方式将其保存到数组中.然后显示整个数组.像排序技术(排序排序等)...
您最好按学生证排序.
Do it in this way.. Read the file using File I/O Strems and then when you display the student information on screan you sort it.. For it you need to read the file into two string variables for this you have to use read method that reads only till a space or end of line occurs and then in a for loop or while loop read the file save the the first line into the first variable and second line in second variable. compare the values using stringcompartion method then save it into an array in sorted way. then You display the whole array. Its Like Sorting tecnique(Buble sort etc)...
You better Sort by Student ID. It is the perfect way.


准确地说,我是一名c#.net学生,但我也有同样的疑问,我已经问过我的教职员工,他们用c#给了我样本.
Actualy i am an c#.net Student but i too had the same doubt i have asked my faculty they gave me the sample in c#.


这将传递ID号,然后对其进行修改以使用姓氏数组的ascii值.

<<整数数组=" sort =">> =
静态void bubble_sort(int [] array)
{
long right_border = array.Length-1;


{
long last_exchange = 0;

对于(long i = 0; i< right_border; i ++)
{
如果(array [i]> array [i + 1])
{
int temp = array [i];
array [i] = array [i + 1];
array [i + 1] = temp;

last_exchange = i;
}
}

right_border = last_exchange;
}
一会儿(right_border> 0);
}
This''ll hand the id number as it, then adapt it to use the ascii value of the surname array.

<<integer array="" sort="">>=
static void bubble_sort( int[] array )
{
long right_border = array.Length - 1;

do
{
long last_exchange = 0;

for (long i = 0; i < right_border; i++)
{
if (array[i] > array[i + 1])
{
int temp = array[i];
array[i] = array[i + 1];
array[i + 1] = temp;

last_exchange = i;
}
}

right_border = last_exchange;
}
while (right_border > 0);
}


这篇关于从文件中排序信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆