二进制转十进制-栈的方式实现
文章目录 二进制转十进制实现 测试 二进制转十进制实现 注意因为使用到了math.h中的函数,编译的时候需要连接数据函数库,即 -lm # include <stdio.h> # include <stdlib.h> # include <math.h> # define STACK_INIT_SIZE 20 # define STACKINCREMENT 10 typedef char ElemType ; typedef struct { ElemType * base ; ElemType * top ; int stackSize ; } sqStack ; void InitStack ( sqStack * s ) ; void Push ( sqStack * s , ElemType e ) ; void Pop ( sqStack * s , ElemType * e ) ; int StackLen ( sqStack s ) ; void InitStack ( sqStack * s ) { s -> base = ( ElemType * ) malloc ( STACK_INIT_SIZE * sizeof ( ElemType ) ) ; if ( ! s -> base ) { exit ( 0 ) ; } s -> top = s -> base