#include #include //201603041067 孔德露
#define stackincreament 10//用來棧的增長
#define maxsize 100
#define overflow -2
#define ok 1
#define error 0
typedef int status;
typedef char selemtype;
typedef struct
sqstack;
//初始化棧
status init(sqstack *s)
//獲取棧頂元素
status gettop(sqstack *s, selemtype e)
//壓棧
status push(sqstack *s, selemtype e)
*s->top++ = e;
return ok;}
//出棧
status pop(sqstack *s, selemtype *e)
//判斷是否為空棧
status stackempty(sqstack *s)
//清空棧
status clearstack(sqstack *s)
//括號匹配演算法
status parenthesis_match(sqstack *s,char *str)
break;
case ']':
break;
default:
break;
}if(flag)
break;
i++;
}if(!flag && stackempty(s))
printf("括號匹配成功!");
else
printf("括號匹配失敗!");
return ok;}
int main()
順序棧實現括號匹配
採用順序棧程式設計實現 表示式的括號是否匹配問題。要求 輸入帶括號的表示式,判斷其中括號是否配對。擴充套件功能 給出配對括號的位序和不配對括號的位序。include include include include include define overflow 2 define stack init...
括號匹配問題 順序棧
思想 每讀入乙個括號 1 若是左括號,則直接入棧,等待相匹配的同類右括號。2 若是右括號,且與當前棧頂的左括號同型別,則二者匹配,將棧頂的左括號出棧,否則屬於不合法的情況。include include define true 1 define false 0 define stack size 5...
順序棧括號匹配問題
使用順序棧解決括號匹配問題 括號匹配問題 包括三種型別的括號 和其他字元,判斷是否存在對應的左右括號 舉例 s 滿足條件 s 不滿足條件 include using namespace std typedef char elemtype const int maxsize 100 struct sq...