配送(ID、重量、...など)のテキストファイルがあり、テキストファイルから読み込んでリストに保存します。私のリストが準備された後、私は正しい順序でそれを並べ替える必要があり、その後私は働くことができます。Cでファイルを読み込んでリストをソートする#
私の質問:テキストファイルからデータを読み取っている間に並べ替えられたリストを取得する方法があるので、ファイルから読み取られる各次の成果物をすぐに適切な場所にリストに挿入する必要があります。
あなたは見ることができます以下の私LoadDeliverablesFromFile
方法:私はmyDeliverables
推測している
public void LoadDeliverablesFromFile(String filename)
{
StreamReader sr = null;
string s;
try
{
sr = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read));
this.myDeliverables.Clear();
s = sr.ReadLine();
while (s != null)
{
string[] words = s.Split(' ');
int id = Convert.ToInt32(words[0]);
int weight = Convert.ToInt32(words[1]);
int buyersID = Convert.ToInt32(words[2]);
Deliverable del = new Deliverable(id, weight, FindPerson(buyersID));
myDeliverables.Add(del);
s = sr.ReadLine();
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
finally
{
if (sr != null) sr.Close();
}
}
myDeliverables.Add(del);リストの最後に追加されます。 InsertAt()を使用して、データを正しい場所に配置します。 – jdweng
Deliverableクラスのどのフィールドにリストを並べ替えるのですか? – Steve
最後にリストをソートすると、どの程度のパフォーマンスが出ますか?不要な最適化の可能性があります。 – James