//二進位制轉換為十進位制
#include
#include
#include
#define ok 1
#define error 0
#define stack_init_size 20
#define stackincrement 10
typedef
char selemtype;
typedef
int status;
typedef
struct
sqstack;
status initstack
(sqstack &s)
s.top = s.base;
s.stacksize = stack_init_size;
return ok;
}status push
(sqstack &s, selemtype e)
s.top = s.base+s.stacksize;
s.stacksize +
= stackincrement;}*
(s.top++
)= e;
return ok;
}status pop
(sqstack &s, selemtype &e)
e =*(
--s.top)
;return ok;
}int
stacklength
(sqstack s)
intmain()
//getchar(); //把'\n'從緩衝區除去(因為原本選定輸入'#'符號表示結束)
len =
stacklength
(stack)
;printf
("棧的當前容量是:%d\n"
, len)
;for
(i =
0; i < len; i++
)printf
("轉換為十進位制數是:%d\n"
, sum)
;return0;
}
#include
#include
#include
#define ok 1
#define error 0
#define stack_init_size 20
#define stackincrement 10
#define maxbuffer 10
typedef
double selemtype;
typedef
int status;
typedef
struct
sqstack;
status initstack
(sqstack &s)
s.top =s.base;
s.stacksize = stack_init_size;
return ok;
}status push
(sqstack &s, selemtype e)
s.top = s.base+s.stacksize;
s.stacksize +
= stackincrement;}*
(s.top++
)= e;
return ok;
}status pop
(sqstack &s, selemtype &e)
e =*(
--s.top)
;return ok;
}int
stacklength
(sqstack s)
intmain()
scanf
("%c"
,&c);if
(' '
== c)
}switch
(c)else
break;}
scanf
("%c"
,&c);}
pop(stack, d)
;printf
("\n最終的計算結果為:%f\n"
, d)
;return0;
}// 計算正常表示式(中綴表示式) 5 - (6 + 7) * 8 + 9 / 4
// 逆波蘭表示式(字尾表示式) 5 6 7 + 8 * - 9 4 / +
// 計算結果 -96.750000
#include
#include
#include
#define ok 1
#define error 0
#define stack_init_size 20
#define stackincrement 10
#define maxbuffer 10
typedef
char selemtype;
typedef
int status;
typedef
struct
sqstack;
status initstack
(sqstack &s)
s.top = s.base;
s.stacksize = stack_init_size;
return ok;
}status push
(sqstack &s, selemtype e)
s.top = s.base+s.stacksize;
s.stacksize +
= stackincrement;}*
(s.top++
)= e;
return ok;
}status pop
(sqstack &s, selemtype &e)
e =*(
--s.top)
;return ok;
}int
stacklength
(sqstack s)
intmain()
}if(')'
== c)
//c==')'在錯寫成c=')'時 無法檢測出錯誤
}elseif(
'+'== c ||
'-'== c)
else
else
}while
(stacklength
(stack)
&&'('
!= e)
;push
(stack, c);}
}elseif(
'*'== c ||
'/'== c ||
'('== c)
elseif(
10== c)
else
scanf
("%c"
,&c);}
while
(stacklength
(stack)
)return0;
}
【額外】 C語言 資料結構 遞迴相關問題
遞迴 int bina search int str,int key,int low,int high if str mid key if str mid key if str mid key include intbina search int str,int key,int low,int hi...
資料結構 棧(C語言)
資料結構 棧 c語言 功能 建棧 出棧 壓棧 判斷棧是否為空 include include define ele int typedef struct stack stack stack newstack 初始化棧 int push stack s,ele value 壓棧 int pop sta...
C語言資料結構 順序棧
順序棧為具有特殊運算操作的順序表,資料通過棧頂先進先出。棧的資料空間和陣列類似儲存固定的一類資料。儲存在連續的空間中,通過出棧和入棧來進行資料操作。具體看下面的函式實現 include define stacksize 20 定義順序棧結構 typedef structseqstack 初始化 vo...