迴圈單鏈表的簡單實現

2021-10-25 17:14:37 字數 1575 閱讀 2964

/*

迴圈單鏈表的實現:

核心操作類似於單鏈表的實現.

此次實現的是帶頭結點的單鏈表

此次實現更加注重函式封裝實現.

*/#include

#include

#define null null

typedef

int elemtype;

typedef

struct lnode node,

*linklist;

//init()

bool initlist

(linklist *l)

(*l)

->next=

(*l);(

*l)->data=null;

return true;

}//empty()

bool isempty

(linklist l)

else

}bool istailnode

(linklist l,node *p)

else

}//後插操作

bool insertnextnode

(node *p,node *s)

s->next=p->next;

p->next=s;

return true;

}node*

inputnode

(elemtype e)

bool createfromhead

(linklist l)

int flag=1;

elemtype ch;

while

(flag)

else

}return true;

}node*

getelem

(linklist l,

int index)

if(index<1)

node *tem=l->next;

int i=1;

while

(tem->next!=l&&iif(i==index)

else

}node*

localelem

(linklist l,elemtype e)

if(tem->data==e)

else

}bool dellist

(linklist l,

int index,elemtype *e)

tem=

getelem

(l,index-1)

;if(tem==null)

if(tem->next==l)

node *p;

p=tem->next;

tem->next=p->next;

return true;

}bool printlist

(linklist l)

printf

("\n");

return true;

}int

main

(int argc,

char

*ar**)

迴圈單鏈表的實現

定義 將單鏈表中終端節點的指標端有空指標改為頭節點,就使整個單鏈表形成乙個環,這種頭尾相接的單鏈表成為單迴圈鍊錶。define maxsize 1000 儲存空間初始分配量 typedef int elemtype typedef int status typedef struct nodenode...

單鏈表簡單實現

單鏈表的形式 頭部有個head節點每個節點都向後關聯乙個節點 下面是我的單鏈表的插刪改查和反轉的操作 include include include typedef struct node list define node size sizeof struct node typedef struct...

單鏈表的簡單實現

include include include define max list length 20 define expand list length 5 using namespace std include include typedef struct node node,list 初始化乙個l...