抽象資料型別的表示與實現

2022-04-29 10:24:12 字數 1723 閱讀 2166

#include

<

string

.h>

//字串函式標頭檔案

#include

<

ctype.h

>

//字元函式標頭檔案

#include

<

malloc.h

>

//malloc()等

#include

<

limits.h

>

//int_max等

#include

<

stdio.h

>

//標準輸入輸出標頭檔案,包括eof(=^z或f6),null等

#include

<

stdlib.h

>

//atoi(),exit()

#include

<

io.h

>

//eof()

#include

<

math.h

>

//數學函式標頭檔案,包括floor(),ceil(),abs()等

#include

<

sys/

timeb.h

>

//ftime()

#include

<

stdarg.h

>

//提供巨集va_start,va_arg和va_end,用於訪問變長參數列

//函式結果狀態**。在教科書第10頁

#define

true 1

#define

false 0

#define

ok 1

#define

error 0

//#define infeasible -1 沒使用

//#define overflow -2 因為在math.h中已定義overflow的值為3,故去掉此行

typedef 

intstatus; 

//status是函式的型別,其值是函式結果狀態**,如ok等

typedef 

intboolean; 

//boolean是布林型別,其值是true或false

*triplet; 

//由inittriplet分配3個元素儲存空間

//triplet型別是elemtype型別的指標,存放elemtype型別的位址

以下是關於抽象資料型別triplet和elemtype的8個基本操作函式: 

抽象資料型別triplet和elemtype(由c1-1.h定義)的基本操作(8個)

status inittriplet(triplet 

&t,elemtype v1,elemtype v2,elemtype v3)

status destroytriplet(triplet &t)

status get(triplet t,

inti,elemtype &e)

status put(triplet t,

inti,elemtype e)

status isascending(triplet t) 

status isdescending(triplet t) 

status max(triplet t,elemtype &e)

status min(triplet t,elemtype &e)

抽象資料型別的表示與實現

各種字元的定義 如下 liyuechao 2014.8.7 c1.h 檔案名字 include include include malloc 等 include int max等 include eof z或f6 null include atoi include eof include floor...

抽象資料型別的表示與實現

typedef elemtype triplet 由inittriplet分配3個元素儲存空間 triplet型別是elemtype型別的指標,存放elemtype型別的位址 status inittriplet triplet t,elemtype v1,elemtype v2,elemtype ...

抽象資料型別的表示與實現

預定義常量和型別 函式結果狀態 define true 1 define false 0 define ok 1 define error 0 define ineasible 1 define overflow 2 status是函式的型別,其值是函式結果狀態 typedef int status...