----寫前:這是乙個做為練習記錄
,別無它用。不足之處還請指正!
這次練習線性鍊錶環境為ubuntu10.10+vim+gcc,分三個檔案,乙個是nodetype.h,node.h,listnode.c。
原始碼如下:
nodetype.h原始碼:
#ifndef _nodetype_h_
#define
_nodetype_h_
#define
ok 1;
#define
error 0;
typedef
intelemtype;
typedef
intstatus;
#endif
node.h原始碼:
#ifndef _node_h_
#define
_node_h_
#include
"nodetype.h
"typedef
struct
lnode
lnode;
status displaylist(lnode
*head);
lnode
*createlist(lnode
*head,
intn);
lnode
*insertelement(lnode
*head,
intposition,elemtype data);
lnode
*getelement(lnode
*head,
intposition);
#endif
listnode.h原始碼:
#include
<
stdio.h
>
#include
<
stdlib.h
>
#include
<
string
.h>
#include
"node.h
"lnode
*createlist(lnode
*head,
intn)
p1->
next
=null;
printf(
"please input the list root data:");
scanf("%d
",&p1
->
data);
return
head;
}status displaylist(lnode
*head)
printf(
"-----------------------------\n");
}lnode
*insertelement(lnode
*head,
intposition,elemtype data)
else
if(null
!=node)}}
return
head;
}lnode
*getelement(lnode
*head,
intposition)
if(null
!=p1)
node
=p1;
}return
node;
}void
main()
displaylist(node);
intpos,val=1
;while
(val
>0)
lnode
*elem;
pos=1;
while
(pos)
free(node);
}以下為部分截圖:
原始碼圖
測試圖注:未完待續(只寫了建立鍊錶、插入、獲取、列印四個函式)
C 單鏈表實現
1 單向鍊錶 單向鍊錶 include include class cnode 節點類 class clist 鍊錶類 cnode movetrail cnode pnode 移動到尾節點 return ptmp void addnode cnode pnode 新增節點 else m nodesu...
c 實現單鏈表
include include using namespace std typedef int datatype struct linknode 建立乙個節點 class slist void swap slist s slist const slist s head null tail null ...
單鏈表(C實現)
ifndef list h define list h typedef struct node node typedef struct list list initlist int insertlist list l,void data,int size node findnodebykey lis...