declartion.h //型別宣告
function.h //函式宣告#define true 1
#define false 0
#define ok 1
#define error 0
#define infeasible -1
#define overflow -2
#define elemtype int
typedef elemtype* triplet;
typedef int status;
function.c //函式的定義#ifndef function_h_included
#define function_h_included
status inittriplet(triplet *t, elemtype v1, elemtype v2, elemtype v3);
//操作結果:構造了三元組t,元素e1, e2, e3分別被賦以引數v1, v2, v3的值
status destroytriplet(triplet *t);
//操作結果:三元組t被銷毀
status get(triplet t, int i, elemtype *e);
//初始條件:三元組t已存在,1<=i<=3;
//操作結果:用e返回t的第i元的值
status put(triplet *t, int i, elemtype e);
//初始條件:三元組t已存在,1<=i<=3;
//操作結果:改變t的第i元的值
status isascending(triplet t);
//初始條件:三元組t已存在;
//如果t的3個元素按公升序排列,則返回1,否則返回0
status isdescending(triplet t);
//初始條件:三元組t已存在;
//如果t的3個元素按降序排列,則返回1,否則返回0
status max(triplet t, elemtype *e);
//初始條件:三元組t已存在;
//操作結果:用e返回t中的3個元素的最大值
status min(triplet t, elemtype *e);
//初始條件:三元組t已存在;
//操作結果:用e返回t中的3個元素的最小值
#endif // function_h_included
main.c#include #include #include "declartion.h"
status inittriplet(triplet *t, elemtype v1, elemtype v2, elemtype v3)
//inittriplet
status destroytriplet(triplet *t)
//destroytriplet
status get(triplet t, int i, elemtype *e)
//get
status put(triplet *t, int i, elemtype e)
//put
status isascending(triplet t)
//isascending
status isdescending(triplet t)
//isdescending
status max(triplet t, elemtype *e)
//max
status min(triplet t, elemtype *e)
//min
執行結果#include #include #include "declartion.h"
#include "function.h"
int main()
if(destroytriplet(t) == ok) printf("destroytriplet success");
return 0;
}
資料結構 佇列(C語言實現)
佇列 c語言實現 include include define queueisempty arg arg size 0 define queueisfull arg arg size arg capacity 判斷是否為空或為滿。巨集定義,函式調銷太大。佇列使用size和capacity顯式的判斷是...
資料結構 C語言實現串
include stdlib.h include stdio.h define true 1 define false 0 define maxlen 255 typedef int status typedef structstring 串的賦值 void strassign string s,c...
資料結構 串(C語言實現)
一.串的定義 串是由零個或者多個字元組成的有限序列。串中任意連續的字元組成的子串行稱為該串的字串,包含字串的串稱為主串。在c語言中,串可以使用如下語句定義 char str hello world 上面的串裡面一共有12個字元,但是編譯器以 0 作為字串結束標誌,所以陣列str的長度為13,串str...