這是給我麻煩的部分。在我的圖中,我指着頭,然後把我的新頭設定爲P,但它在現實生活中並沒有成功。有什麼建議麼?鏈接列表推前不能正常工作
{
// p points to a new node
Node *p = new Node(s,0);
if(head == 0) // head not pointing to a node yet?
{
head = tail = p; // head & tail point to new node in the list
}
else
{ // head->next points to new node
head = p-> get_next();
head = p;
// head points to first node in the list
}
這裏是get_next()
函數。
Node *Node::get_next() const // get a Node * (value of next)
{
return next; //returns current objects pointer to next
}
我試圖在以前的一些情況我心中已經看到網上看,我開始懷疑我的get_next()
是錯誤的。不幸的是我必須用它來完成這項任務。
只要你將它設置爲p-> next – 2014-10-30 02:51:05
在其他部分中,你就會用p覆蓋頭部//就像這樣評論// head-> next指向新節點,但是分配p-> next頭,而不是頭 - >下一頁= p – 2014-10-30 02:55:21
[MCVE](http://stackoverflow.com/help/mcve)請!是的,我是一個代碼納粹,如果有人對此有所懷疑! – 2014-10-30 02:55:56