單鏈表可以說是基礎,有利於對指標的使用
結點:
typedef int datatype;
typedef struct slistnode
slistnode;
實現的函式的宣告如下:
slistnode* _buynode(datatype x);
void printslist(slistnode* phead);
void pushback(slistnode** phead, datatype x);
void popback(slistnode*& phead);
void pushfront(slistnode*& phead, datatype x);
void popfront(slistnode*& phead);
slistnode* find(slistnode* phead, datatype x);
void insert(slistnode* pos, datatype x);
void erase(slistnode*& phead, slistnode* pos);
具體實現如下:
slistnode* _buynode(datatype x)
void printslist(slistnode* phead)
printf("null\n");
}void pushback(slistnode** phead, datatype x)
else
slistnode* tmp = _buynode(x);
cur->next = tmp; }}
void popback(slistnode*& phead)
else if (phead->next == null)
else }
void pushfront(slistnode*& phead, datatype x)
else }
void popfront(slistnode*& phead)
else if (phead->next == null)
else }
slistnode* find(slistnode* phead, datatype x)
cur = cur->next;
} return null;
}void insert(slistnode* pos, datatype x)
void erase(slistnode*& phead, slistnode* pos)//刪除的時候判斷:1、刪除的是否為頭結點2.刪除的不是頭結點
else
} }
}
測試用例:
只寫erase的測試用例
void test()
c語言實現單鏈表
一 使用簡介 使用c語言實現了單鏈表的基本操作,共有四個檔案,兩個標頭檔案是常用的,後兩個分別是主函式,和對鍊錶的基本操作函式,倒入時候,須將四個檔案放在同乙個目錄下。二 心得 在書寫過程中,主要錯誤集中在指標的使用上,通過此次程式設計,對於指標的認識更加深刻,頭結點的存在,更大意義上是為了簡化指標...
C語言實現單鏈表
dev c 編譯執行通過,實現了單鏈表的構建,清空,插入,刪除和查詢。include include include include include define ok 1 define error 0 typedef int elemtype typedef struct node node ty...
單鏈表C語言實現
單鏈表相比於順序表來說,優點在於頭部,中間插入比較高效,但操作較為複雜,空間利用率低,並且cpu順序錶比鍊錶快取效率高。下面來看 實現 include include includetypedef int datatype typedef struct node pnode,node 初始化單鏈表 ...