順序線性表

2021-07-11 10:54:26 字數 1907 閱讀 9624

#define true    1

#define false 0

#define ok 1

#define error 0

#define infeasible -1

#define overflow -2

#define list_init_size 100

#define list_increment 10

typedef int status;

//elemtype也可以定義為其它型別

typedef structelemtype;

#define key age //key為排序的的依據

//typedef順序線性表型別

typedef struct listtype;

// 建乙個空的順序線性表

status initlist(listtype &l)

l.length=0;

l.listsize=list_init_size;

return ok;

}//釋放乙個順序線性表

status destroylist(listtype &l)

free(l.elem );

l.elem=null;

l.length=0;

l.listsize =0;

return ok;

}//重置乙個順序線性表

status clearlist(listtype &l)

l.length =0;

return ok;

}//檢查順序線性表是否為空

status listempty(listtype l)else

}//測量線性表長度

status listlength(listtype l,int &n)

n=l.length;

return ok;

}//取下標i-1的元素並賦給e

status getelem(listtype l, int i, elemtype & e)

i--;

e=l.elem[i];

}//在順序線性表中第i-1處插入乙個元素e

status listinsert(listtype &l,int i,elemtype e)

i--;

int j;

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

l.elem[i]=e;

l.length++;

return ok;

}//列印順序線性表中所有元素

status listprint(listtype l)

int i;

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

return ok;

}//順序線性表公升序排序

status sortlist(listtype &l)

int is_exchanged=1;

int i,len;

len=l.length;

elemtype t;

while (is_exchanged) }}

return ok;

}

//將la和lb公升序排列並賦給lc

status mergelist(listtype la,listtype lb,listtype &lc)

while(la_point<=alength&&lb_point<=blength)else

} while(la_point<=alength)

while(lb_point<=blength)

return ok;

}

順序線性表

sequential linear list this file define the ds of sequential linear list s basic operation,it includes linear list insert,delete,initial,and sort oper...

順序線性表

include int const maxsize 100 typedef int element typedef struct list element list get index value list int int main 函式 初始化線性表 void list init list ls ...

順序線性表

線性表的順序表示和實現 線性表的順序表示指的是用一組位址連續的儲存單元依次儲存線性表的資料元素。線性表的第乙個資料元素a1的儲存位置,通常稱作線性表的起始位置或基位址。只要確定了儲存線性表的起始位置,線性表中任一資料元素都可隨機訪問,所以線性表的順序儲存結構是一種隨機訪問的儲存結構。陣列型別有隨機訪...