对于作业,我必须按部门按字母顺序对一堆员工进行排序。
例如:
David
Hunter
1
Admin
John
Smith
11
Sales
Jane
Appleby
5
Accounts
Michelle
Page
12
Sales
Peta
Jones
13
Admin
应该成为
Jane
Appleby
5
Accounts
David
Hunter
1
Admin
Peta
Jones
13
Admin
John
Smith
11
Sales
Michelle
Page
12
Sales
我想为此使用bubblesort但我不知道如何使用除名字之外的任何东西进行排序。这就是我到目前为止所做的:
string[] people = record.Split(new string[] { "\r\n\r\n" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string person in people)
{
string[] details = person.Split('\n');
firstName = details[0];
lastName = details[1];
empID = details[2];
department = details[3];
}
for (int i = 1; i < people.Length; i++)
{
for (int j = 0; j < people.Length - i; j++)
{
//people.department doesn't work
if (people.department[j].CompareTo(people.department[j + 1]) > 0)
{
temp = people[j];
people[j] = people[j + 1];
people[j + 1] = temp;
}
}
}
是否有可能做我正在尝试使用像这样的bubbleort,并访问员工的部门?我应该考虑其他可能更好/更简单的方法吗?