C語言 棧模版

2021-10-20 02:19:54 字數 660 閱讀 6391

要實現逆波蘭表示式+高精度字串的計算器,棧必不可少

c語言缺少各種資料結構庫,於是寫了乙個棧

這裡的elemtype是棧中元素的型別,我要存放的是長度很大的字串指標,所以用的是char*

別的情形下更改,即可實現各種型別的棧

#include#include#include#include#define stack_staize 500

typedef char* elemtype;

typedef struct

stack;

void stack_init(stack *sta); //初始化棧

int stack_push(stack *sta,elemtype e);//push

int stack_pop(stack *sta);//pop

elemtype stack_top(stack *sta)

void stack_init(stack *sta)

int stack_push(stack *sta,elemtype e)

int stack_pop(stack *sta)

int stack_size(stack *sta)

int main()

C語言實現模版

c語言有兩把雙刃劍,一把是 指標 另一把是 巨集 這回咱就用 巨集 來實現c 中才有的模版。這裡的模版實現乙個很簡單的加法函式,同乙個函式 可以處理不同型別的加法運算。c 的實現 template t add t a,t b include int main int argc,const char ...

C語言巨集實現模版函式

h檔案可以宣告巨集定義模版函式 在其它檔案中只要包含了該.h檔案,就可以使用這些函式 define convert declare suffix,t,filename extern void suffix filename const scalar s,t buf,int cn,int unroll...

高精度運算模版C語言

include include include include define maxx 100 using namespace std 高精度加法 void add char s1,char s2 b maxx 10 int l1 strlen s1 int l2 strlen s2 for i l...