.h檔案宣告
//
// created by sanzhixiong on 2017/10/31.
//#ifndef day14_linklist_h
#define day14_linklist_h
//節點操作
typedef struct node
*pnode;
//建立頭
pnode createlinkhead();
//列印
void printlinklist(pnode phead);
//插入
void install_list(pnode phead,int num,int value);
//刪除
void del_list(pnode phead,int num);
#endif //day14_linklist_h
.c檔案
//
// created by sanzhixiong on 2017/10/31.
//#include "linklist.h"
#include #include //節點的操作
pnode createlinkhead()
printf("請輸入節點個數\n");
scanf("%d",&len);
if(len<0)
ptitle = phand;
phand->pnext = null;
for (i = 0; i data = value;
ptitle->pnext = p;
p->pnext = null;
ptitle = p;}}
return phand;
}//列印函式
void printlinklist(pnode phead)
head = phead;
while(head!=null)
}//插入函式
void install_list(pnode phead,int num,int value)
pnode phead = phead;
//核心
while(phead != null)
p->data = value;
if(phead->pnext)
else
}phead = phead->pnext;
i++;
}}void del_list(pnode phead,int num)
phead = phead;
while(phead != null)}}
phead = phead->pnext;
i++;
}}
測試main檔案
#include #include #include "linklist.h"
int main()
printlinklist(phead);
printf("插入前列印\n");
install_list(phead,2,3);
printf("插入後的列印\n");
printlinklist(phead);
del_list(phead,0);
printf("刪除以後列印\n");
printlinklist(phead);
return 0;
}
鍊錶學習 靜態鍊錶
struct linknode 鍊錶在指定位置插入與刪除元素不需要移動元素,只需要修改指標即可,而陣列刪除與加入元素則需要移動後面的元素,鍊錶相對於陣列來講,則多了指標域空間開銷,拿到鍊錶第乙個節點就相當於拿到整個鍊錶 鍊錶的分類 靜態鍊錶,動態鍊錶 單向鍊錶,雙向鍊錶,迴圈鍊錶,單向迴圈鍊錶,雙向...
靜態鍊錶(陣列 鍊錶和靜態鍊錶的操作)
因為是線性表,不能只講鍊錶,所以今天提一下靜態鍊錶以及陣列 鍊錶 靜態鍊錶之間的對比。陣列基本結構沒得說,插入和刪除的操作也是有的 雖然看著不比較詭異 一般是動態分配乙個足夠長的,記錄有多少個元素後對這個個數進行加減,而不是每插入乙個就動態分配 其實這樣也行,要是不怕麻煩的話 另外在插入刪除操作之後...
靜態鍊錶和迴圈鍊錶
所謂靜態鍊錶,與指標型描述的鍊錶 動態鍊錶 的區別在於靜態鍊錶借用一維陣列來描述鍊錶.這種儲存型別需要預先分配乙個較大的空間.其結構如下圖 與動態鍊錶操作時最大的區別在於 靜態鍊錶需由使用者自己實現malloc和free函式.為了辨明陣列中哪些分量未被使用,解決的辦法是 將所有未被使用過的以及被刪除...