我需要幫助編寫一個程序,該程序需要三個單獨字段的學生信息(ID Number, first name, last name)
。然後,根據last name
字段按字母順序對錶格進行排序。用戶將輸入學生數據,然後我希望它將last name
數據分成兩個桶,然後將其置於氣泡排序中。我無法將數據添加到單獨的存儲桶中。使用字符串作爲值在C#中編寫桶排序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _123_Assignment2
{
using System;
using static System.Console;
class Program
{
struct student
{
public int studentId;
public string firstName;
public string lastName;
};
static void Main(string[] args)
{
student[] studentInfo = new student[20];
string[] bucketLow = new string[0];
string[] bucketHigh = new string [0];
int x = 0;
int y = 0;
WriteLine("Enter student ID number:");
studentInfo[x].studentId = Convert.ToInt32(ReadLine());
while (studentInfo[x].studentId != 999)
{
WriteLine("Enter first name:");
studentInfo[x].firstName = ReadLine();
WriteLine("Enter last name:");
studentInfo[x].lastName = ReadLine();
x++;
WriteLine("Enter student ID number:");
studentInfo[x].studentId = Convert.ToInt32(ReadLine());
}
for (int j = 0; j < studentInfo.Length; j++)
{
if (studentInfo[j].lastName.CompareTo(studentInfo[j + 1].lastName) > 0)
bucketLow[y] = studentInfo[j].lastName;
else
bucketHigh[y] = studentInfo[j].lastName;
y++;
}
}
}
}
功課,考慮** **的Linq' –
「我有麻煩」' - 什麼麻煩?具體是什麼問題? – David
如果你不做家庭作業,而且你實際上正在編寫自己的泡泡分類,那麼你做錯了。 –