採用書上第93頁定義的陣列的順序儲存表示,程式設計實現陣列的下列基本操作
(1) 構造陣列 (2)銷毀陣列 (3)取陣列元素值 (4) 給陣列元素賦值
2.採用書上第98頁定義的稀疏矩陣的三元組順序表儲存表示,程式設計實現矩陣的轉置運算演算法和快速轉置演算法。
7.1
7.2#include
#include
#include
#include
#include
#define true 1
#define false 0
#define ok 1
#define error 0
#define infeasible -1
#define overflow -2
#define max_array_dim 8
typedef
int status;
typedef
int boolean;
typedef
int elemtype;
typedef
struct
array;
status initarray
(array* a,
int dim,..
.)va_end
(ap);(
*a).base =
(elemtype*
)malloc
(elemtotal *
sizeof
(elemtype));
if(!(
*a).base)
exit
(overflow);(
*a).constants =
(int*)
malloc
(dim *
sizeof
(int))
;if(!
(*a)
.constants)
exit
(overflow);(
*a).constants[dim -1]
=1;for
(int i = dim -
2; i >=0;
--i)
(*a)
.constants[i]=(
*a).bounds[i +1]
*(*a).constants[i +1]
;return ok;
}status destroyarray
(array* a)
else
return error;if(
(*a)
.bounds)
else
return error;if(
(*a)
.constants)
else
return error;
return ok;
}status locate
(array a, va_list ap,
int* off)
return ok;
}status value
(array* a, elemtype* e ,..
.)status assign
(array* a, elemtype e,..
.)intmain()
#include
#include
#include
#define maxsize 12500
#define mu 5
#define nu 6
#define ok 1
typedef
struct
triple;
typedef
struct
tsmatrix;
intcreatematrix
(tsmatrix &m)
if(k-
1==m.tu)
return ok;
}return ok;
}void
(tsmatrix m)
}int
transposesmatrix
(tsmatrix m,tsmatrix &t)
}return ok;
}int
fasttransposesmatrix
(tsmatrix m,tsmatrix &t)
;int cpot[nu+1]
=;int p,q,col;
for(q=
1;q<=m.tu;q++
) num[m.data[q]
.j]++
; cpot[1]
=1;for
(q=2
;q<=m.nu;q++
) cpot[q]
=cpot[q-1]
+num[q-1]
;for
(p=1
;p<=m.tu;p++
)return ok;
}int
main()
《資料結構》 順序陣列的實現和表示
陣列的特點 結構固定 定義後,維數和維界不再改變 陣列的基本操作 除了結構的初始化和銷毀之外,只有取元素和修改元素值的操作。include include include include include 標準標頭檔案,提供巨集va start,va arg和va end,用於訪問變長參數列 incl...
資料結構 棧的陣列表示
棧 棧 stack 又名堆疊,它是一種運算受限的線性表。限定僅在表尾進行插入和刪除操作的線性表。這一端被稱為棧頂,把另一端稱為棧底。向乙個棧插入新元素又稱作進棧 入棧或壓棧,它是把新元素放到棧頂元素的上面,使之成為新的棧頂元素。從乙個棧刪除元素又稱作出棧或退棧,它是把棧頂元素刪除掉,使其相鄰的元素成...
資料結構 鏈式棧的表示和實現
鏈式棧的表示和實現 鏈式棧 採用鏈式的儲存結構實現的棧 通常使用單鏈表的形式 2019.04.15 include include include using namespace std define ok 1 define error 0 define overflow 1 typedef int...