對於我的編程類我必須手動進行鏈接的列表和它的一些方法,我需要插入排序的項目,這是我寫的代碼是:數組動態列表C#
public bool Insert(Project project)
{
bool gotInserted = true;
if (IsInList(project) == true)
{
gotInserted = false;
}
else
{
Node tmp = this._head;
this._head = new Node();
this._head.Project = project;
this._head.Next = tmp;
//SortList(); //is commented, because this method causes problems
}
return gotInserted;
我可以有更好的方法來插入節點排序?
節點級:
public class Node
{
Project _project;
Node _next;
public Project Project
{
get { return _project; }
set { _project = value; }
}
public Node Next
{
get { return _next; }
set { _next = value; }
}
對不起語法不好,我是奧地利人,並在我的空閒時間我通常沒有用英語思考。
你的意思是你現在有一個鏈接列表。爲了讓它排序,你首先必須尋找適當的部分來插入。爲什麼不使用List <>? – RvdK
我猜測,因爲這是一個類,他必須創建自己的自制版本的List <>'而不是僅僅使用現有的框架。 – ppalms
如果此代碼有效,但排序會導致問題,請顯示排序代碼及其導致的問題。 – CodeCaster