資料結構之鍊錶

2022-03-31 10:06:54 字數 3066 閱讀 8513

資料結構。之。鍊錶的實現。

基礎篇;

鍊錶的建立和輸出:

#include //

順序表的定義:

#define listsize 100 //

表空間大小可根據實際需要而定,這裡假設為100

typedef

int datatype; //

datatype可以是任何相應的資料型別如int, float或char

typedef struct

seqlist;

void

main()

//順序表的建立:

void createlist(seqlist *l,int

n)//

順序表的列印:

void printlist(seqlist l,int

n)

view code

鍊錶的查詢:

#include #include 

//順序表的定義:

#define listsize 100 //

表空間大小可根據實際需要而定,這裡假設為100

typedef

int datatype; //

datatype可以是任何相應的資料型別如int, float或char

typedef struct

seqlist;

void

main()

//順序表的查詢:

intlocatelist(seqlist l,datatype x)

//順序表的列印:

void printlist(seqlist l,int

n)

view code

鍊錶的插入:

#include #include 

//順序表的定義:

#define listsize 100 //

表空間大小可根據實際需要而定,這裡假設為100

typedef

int datatype; //

datatype可以是任何相應的資料型別如int, float或char

typedef struct

seqlist;

void

main()

//順序表的插入:

void insertlist(seqlist *l,datatype x,int

i)

if ((*l).length>=listsize)

for (j=(*l).length-1;j>=i-1;j--)

(*l).data[j+1]=(*l).data[j];

(*l).data[i-1]=x;

(*l).length++;}//

順序表的列印:

void printlist(seqlist l,int

n)

view code

鍊錶的刪除:

#include #include 

//順序表的定義:

#define listsize 100 //

表空間大小可根據實際需要而定,這裡假設為100

typedef

int datatype; //

datatype可以是任何相應的資料型別如int, float或char

typedef struct

seqlist;

void

main()

//順序表的刪除:

void deletelist(seqlist *l,int

i)

for (j=i;j<=(*l).length-1;j++)

(*l).data[j-1]=(*l).data[j];

(*l).length--;}//

順序表的列印:

void printlist(seqlist l,int

n)

view code

然後,是大集合,把之前的都合到一起;

#include #include 

//順序表的定義:

#define listsize 100 //

表空間大小可根據實際需要而定,這裡假設為100

typedef

int datatype; //

datatype可以是任何相應的資料型別如int, float或char

typedef struct

seqlist;

//順序表的建立:

void createlist(seqlist *l,int

n)//

順序表的列印:

void printlist(seqlist l,int

n)//

順序表的查詢:

intlocatelist(seqlist l,datatype x)

//順序表的插入:

void insertlist(seqlist *l,datatype x,int

i)

if ((*l).length>=listsize)

for (j=(*l).length-1;j>=i-1;j--)

(*l).data[j+1]=(*l).data[j];

(*l).data[i-1]=x;

(*l).length++;}//

順序表的刪除:

void deletelist(seqlist *l,int

i)

for (j=i;j<=(*l).length-1;j++)

(*l).data[j-1]=(*l).data[j];

(*l).length--;

}void

main()

適合初學者理解和研究;

資料結構 表之煉表

頭插法建立 尾插法建立 顯示 銷毀 include include using namespace std typedef int elemtype typedef struct lnode linklist void createlinklistf linklist l,elemtype a,in...

資料結構之鍊錶

頭結點 第乙個有效結點之前的那個結點 頭結點並不存有效資料 加頭結點的目的主要是為了方便對鍊錶的操作 頭指標 指向頭結點的指標變數 尾指標 指向尾節點的指標變數 如果希望通過乙個函式對鍊錶進行處理,只需要乙個引數 頭指標 首先要定義乙個單鏈表儲存結構 然後建立乙個空表,即初始化,我寫的這個提前設定好...

資料結構之鍊錶

鍊錶是一種基本的資料結構型別,它由乙個個結點組成。每乙個結點包括乙個資料的儲存和乙個指向下乙個結點的引用。在這個定義中,結點是乙個可能含有任意型別資料的抽象實體,它所包含的指向結點的應用顯示了它在構造鍊錶之中的作用。和遞迴程式一樣,遞迴資料結構的概念一開始也令人費解,但其實它的簡潔性賦予了它巨大的價...