typedef int datatype;
typedef struct listnode
listnode;
注:1.以下函式都是針對無環單鏈表
2.若可能修改到原煉表頭結點,都要傳二級指標
函式如下:
listnode* buynode(datatype x); //開闢新節點
void pushback(listnode** list, datatype data); //尾插
void popback(listnode** list); //尾刪
void pushfront(listnode** list, datatype data); //頭插
void popfront(listnode** list); //頭刪
void insert(listnode** pplist, listnode* pos, datatype data); //定點插入
void erase(listnode** pplist, listnode* pos); //定點刪除
void printlist(listnode* list); //列印
listnode* find(listnode* plist, datatype data); //查詢
void destorylist(listnode** pplist); //釋放單鏈表(若有環,先解環)
1.開闢新節點
listnode* buynode(datatype x)
2.尾插
void pushback(listnode** pplist, datatype data)
else
tail -> next = buynode(data);
}}
3.尾刪
void popback(listnode** pplist)
else if ((*pplist) -> next == null)
else
free(tail);
prev -> next = null;
}}
4.頭插
void pushfront(listnode** pplist, datatype data)
else
}
5.頭刪
void popfront(listnode** pplist)
else if ((*pplist)-> next == null)
else
}
6.定點插入
void insert(listnode** pplist, listnode* pos, datatype data)
else
prev -> next = buynode(data);
(prev -> next) -> next = pos;
}}
7.定點刪除
void erase(listnode** pplist, listnode* pos)
else if (pos -> next == null)
else
prev -> next = pos -> next;
free(pos);
}}
8.列印
void printlist_r(listnode* plist)
printlist_r (plist -> next);
printf("%d->", plist -> data);
}
9.查詢
listnode* find(listnode* plist, datatype data)
cur = cur -> next;
} return null;
}
10.釋放
void destorylist(listnode** pplist)
*pplist = null;
}
單鏈表的增刪查改(C語言實現)
ifndef common h define common h include include include include include pragma warning disable 4996 endif common h ifndef slist h define slist h inclu...
c語言單鏈表增刪查
ifndef linklist h define linklist h include include include include typedef unsigned char datatype typedef struct node linknode linknode createlink da...
C語言單鏈表 增刪查
廢話不多說直接看 內建詳細注釋 結點結構 typedef struct node node,linklist 起別名,乙個正常別名,乙個指標別名 單鏈表查詢演算法 linklist find list linklist l,int k if p i k return null 否則查詢元素不存在 單...