我正在使用鏈接列表並嘗試在where'th節點後面插入一個帶有數據d的新節點。出於某種原因,我得到不正確的結果。這裏是我的代碼:在第n個元素後面插入鏈接列表
void insertAfter(int d, int where)
{
struct list * marker = head;
struct list * new;
while(marker -> data != where)
marker = marker -> next;
new = (struct list*)malloc(sizeof(struct list));
new -> next = marker -> next;
marker -> next = new;
new -> data = d;
}
'marker - > data!=其中'不代表第n個 – BLUEPIXY