順序表的基本操作(C語言)

2021-04-12 22:44:13 字數 723 閱讀 6261

#define list_init_size 100  //線性表初始分配量

#define listincreament 10   //分配增量

#include

#include

typedef struct sqlistsqlist;//定義線性表

void creat_sqlist(sqlist &l)

//判斷表是不是空表

void getelem_sqlist(sqlist l,int i,int &e)

//取線性表中的第i個元素

void delete_sqlist(sqlist &l,int i,int &e)

int *p=&(l.elem[i-1]);//p為插入元素位置

int *q=&(l.elem[l.length]);//線性表最後乙個元素的位置

for(q;q>=p;q--) *(q+1)=*q;

*p=e;

l.length++;

}//把元素e插入到位置i前

int locate_sqlist (sqlist l,int e)

//求前驅(找到cur_e的前驅,用pre_e儲存)

void nextelem(sqlist l,int cur_e,int &next_e)

//求後繼

printf("輸出線性表中的元素");

for(int i=0;ireturn 0;

}

順序表的基本操作(C語言)

順序表是指線性表的順序表示,指的是用一組位址連續的儲存單元依次儲存線性表的資料元素。只要確定了順序表的起始位置,順序表的任一資料元素都可以隨機訪問,線性表的順序儲存結構是一種隨機訪問的儲存結構。在這點上與高階程式語言中的陣列十分相似,因此通常用陣列來描述資料結構中的順序儲存結構。下面是在學習浙大資料...

順序表基本操作實現 c語言

include include include define max size 100 typedef int elemtype typedef struct node seqlist 初始化乙個空的順序表 seqlist initseqlist l length 0 printf 順序表初始化成功...

動態順序表的基本操作(c語言)

include include 使用malloc函式要包含這個檔案 include define init capacity 10 初始化時分配的容量 typedef struct seqlistseqlist void seqlist init seqlist list 初始化順序表 void c...