linkedlist(c语言_简单实现)
生活随笔
收集整理的這篇文章主要介紹了
linkedlist(c语言_简单实现)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1 #include<stdlib.h>
2 typedef char Ele ;
3
4 typedef struct node{
5 Ele e;
6 struct node *next;
7 }lnode,*list;
8
9 void get(Ele);
10
11 //構造鏈表
12 list createlist(int n){
13 list l = NULL;
14 lnode *p,*r=NULL;
15 Ele e;
16 int i;
17 for(i=0;i<n;i++){
18 get(e);
19 p = (lnode *)malloc(sizeof(lnode));
20 p->e=e;
21 //構造首元素
22 if(!list){
23 l->e=p;
24 }else{
25 r->next=p;
26 }
27 r=p;
28 }
29 return l;
30 }
31
32 //插入節(jié)點
33 void insertList(list list,lnode *q,Ele e){
34 lnode *p = (lnode *)malloc(sizeof(lnode));
35 p->e=e;
36 if(!list){
37 list->next=p;
38 p->next=NULL;
39 }else{
40 //將后一個節(jié)點賦值給p.next,前一個節(jié)點的下一個節(jié)點賦值給p
41 p->next=q->next;
42 q->next=p;
43 }
44 }
45
46 //刪除節(jié)點
47 void delNode(list l,lnode *q){
48 if(l==q){
49 l=q->next;
50 }else{
51 list temp = list;
52 while((temp=temp->next)!=q && temp!=NULL){
53 }
54 temp->next=q->next;
55 free(q);
56 }
57 }
58
59 //銷毀鏈表
60 void destorylist(list list){
61 lnode *p,*q;
62 p=list;
63 while(p){
64 q=p->next;
65 free(p);
66 p=q;
67 }
68 list=NULL;
69 }
?
轉載于:https://www.cnblogs.com/mozhuhao/p/4484875.html
總結
以上是生活随笔為你收集整理的linkedlist(c语言_简单实现)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python开发入门与实战1-开发环境
- 下一篇: 题目1049:字符串去特定字符