靜態鍊錶的初始化 插入 刪除

2021-08-14 04:27:16 字數 1471 閱讀 3681

#include #include #define ok 1

#define true 1

#define error -1

#define false -1

#define overflow -2

#define elemtype int

#define status int

//------靜態鍊錶 x 使用陣列實現鍊錶,可以在沒有指標的程式語言中實現鍊錶結構

#define maxsize 1000 //假設鍊錶的最大長度是1000

//封裝 靜態鍊錶

typedef struct

component, staticlinklist[maxsize]; //宣告為staticlinklist[max_size]

//初始化靜態鍊錶

status initlist(staticlinklist space) //將一維陣列space中各分量鏈成一備用鍊錶

//靜態鍊錶的插入操作

//1、建立malloc()函式

int malloc_sll(staticlinklist space)

//靜態鍊錶長度函式:即l中元素個數

int listlength(staticlinklist l)

return j;

}//2、插入操作(不移動元素,卻插入了資料)

//在l中第i個元素之前插入新的資料元素e

status listinsert(staticlinklist l, int i, elemtype e)

return error;

}//靜態鍊錶的刪除操作

//1、建立free()函式

//將下標為i的空閒結點**到備用列表

void free_ssl(staticlinklist space, int i)

//2、刪除操作

//刪除在l中第i個元素e

status listdelete(staticlinklist l, int i)

typedef struct lnode

lnode,*linklist;

這其實是兩步:

1、定義結構體:

struct lnode

;至於struct lnode *next;是定義乙個struct lnode結構體型別的指標,當然要有struct lnode了。就像定義int型,要用int一樣。

2、定義型別 lnode:

typedef struct lnode lnode;

就是定義新的型別lnode,即:struct lnode的別名。為了方便呼叫,少打字。

3、定義型別 linklist指標:
typedef struct lnode *linklist;

靜態鍊錶 初始化 插入

include include define ok 1 define true 1 define error 1 define false 1 define overflow 2 define elemtype int define status int 線性單鏈表 初始化 插入 取出 頭插法 合併...

迴圈鍊錶的初始化,插入與刪除

迴圈鍊錶與普通鍊錶相比,區別在於尾結點的next指向頭結點,當鍊表為空時,頭結點的next指向自身 如下 鍊錶的初始化 package list public class circlelinklist 鍊錶的順序新增 public void circlelinklist add object dat...

靜態順序表的初始化以及插入刪除操作

在編寫之前首先需要說明,在使用c語言編寫時,在自定義外函式 也就是在main函式體之外 體內不能使用 符號以及 符號,取而代之的是 號以及 符號 1.首先是靜態順序表結構體的編寫 typedef struct sqlist 2.初始化 void initlist sqlist l 3.插入操作 bo...