無頭結點的鍊錶實現

2021-08-22 07:21:56 字數 668 閱讀 9139

鍊錶的插入(任何位置):

int link1insert(node **l, int p, int e)

else if(((null == *l) && (p > 1)) || (p < 1))

else

if(p > count + 1)

return failure;

else if(p == count + 1)

else if(p < count + 1 && p > 1)

n->next = q->next;

q->next = n;

n->data = e;

return success;

}else

}}

我用的是if條件判斷語句去把是不是插入第乙個位置,不含有頭結點的鍊錶和有頭結點的鍊錶的區別就在於是否是插入第乙個位置,如果插入的是第乙個位置就改變頭指標的指向。所以要傳入位址。上面我寫的這種方法可能不是最簡潔的方法。

鍊錶倒序:

int linkreverse(node *l)

node *p = l->next;

l->next = null;

while(p != null)

return failure;

}

無頭結點鍊錶

include include linklist.h struct node create linklist creat linklist 根據使用者輸入,建立乙個單鏈表 struct node pnew struct node malloc sizeof struct node pnew data...

頭結點鍊錶練習

這是乙份關於頭結點鍊錶的問題 完成一些基本的煉表處理函式,包括插入,查詢,刪除,輸出等一些功能的實現 include include include linklist.h node creat list 尾插法 int insert last node head,linkdata data 頭插法 ...

鍊錶的虛擬頭結點

public class linkedlist public node e e public node override public string tostring 虛擬頭結點 private node dummyhead private int size public linkedlist 獲取...