数据结构<help!!>
public void Append(T item){
//Node<T>结点类。 Node<T> 里有 Data(数据) - Next(指针) 两个属性
Node<T> q = new Node<T>(item); // 数据=item , 指针=null
Node<T> p = new Node<T>(); // 数据=default , 指针=null
// head代表单链表的第一个只有指针域的
if (head == null)
{
head = q;
return;
}
p = head;
while (p.Next != null)//head 不为空时, ----- 我怎么越想越觉着head 的NEXT 永远为 Null
{
// -------- 问题所在我怎么看怎么感觉这里永远进不去,代码一直没影响head的next属性==^^^^^^
// 而声明的变量 p 等于head 后 永远 next = null 了, 那位高手帮下小弟。
p = p.Next;
}
p.Next = q;
} --------------------编程问答--------------------
public void Append(T item)--------------------编程问答-------------------- 代码不要"想",不要"觉得".自己亲手编译一次执行不就都清楚了嘛... --------------------编程问答-------------------- Data 是 T 泛型 ,
{
//Node<T>结点类。 Node<T> 里有 Data(数据) - Next(指针) 两个属性
Node<T> q = new Node<T>(item); // 数据=item , 指针=null
Node<T> p = new Node<T>(); // 数据=default , 指针=null
// head代表单链表的第一个只有指针域的
if (head == null)
{
head = q;
return;
}
p = head;
while (p.Next != null)//head 不为空时, ----- 我怎么越想越觉着head 的NEXT 永远为 Null
{
// -------- 问题所在我怎么看怎么感觉这里永远进不去,代码一直没影响head的next属性==^^^^^^
// 而声明的变量 p 等于head 后 永远 next = null 了, 那位高手帮下小弟。
p = p.Next;
}
p.Next = q;
}
Next是 Node 类型的 --------------------编程问答-------------------- C#好像很少用链表了,要使用指针就需要不安全代码。
画个链表图,自己用箭头挪挪看就明白了
补充:.NET技术 , C#