#include<string.h> // 字串函式頭檔案
#include<ctype.h> // 字符函式頭檔案
#include<malloc.h> // malloc()等
#include<limits.h> // INT_MAX等
#include<stdio.h> // 標準輸入輸出頭檔案,包括EOF(=^Z或F6),NULL等
#include<stdlib.h> // atoi(),exit()
#include<io.h> // eof()
#include<math.h> // 數學函式頭檔案,包括floor(),ceil(),abs()等
#include<sys/timeb.h> // ftime()
#include<stdarg.h> // 提供宏va_start,va_arg和va_end,用于存取變長引數表
// 函式結果狀態代碼。在教科書第10頁
using namespace std;
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define OK 1
#define ERROR 0
#define STACK_INIT_SIZE 100;
#define STACKINCERMENT 10;
typedef int Status;
typedef int SElemType;
typedef struct{
SElemType *base;
SElemType *top;
int stacksize;
}Sqstack;
Status InitStack(Sqstack &S)//創建空的堆疊;
{
S.base=(SElemType * ) malloc(100 * sizeof(SElemType));
if(!S.base)exit(ERROR);
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
return OK;
}
Status GetTop(Sqstack S,SElemType &e)//若堆疊不為空,就回傳堆疊頂;
{
if(S.base==S.top) return ERROR;
e=*(S.top-1);
return OK;
}
Status Push(Sqstack &S,SElemType e)
{
if(S.top-S.base>=S.stacksize){
S.base=(SElemType * )realloc(S.base,(S.stacksize+100) *sizeof(SElemType));
}
if(!S.base)exit(OVERFLOW);
S.top=S.base+S.stacksize;
S.stacksize+=STACKINCERMENT;
}
Status Pop (Sqstack &S,SElemType &e)
{
if(S.top==S.top) return ERROR;
e=*(--S.top);
return OK;
}
Status matching(string & exp)
{ int i=0;
int state = 1;
SElemType e,S;
while (i<=sizeof(exp) && state) {
switch exp[i] {
case "(":{Push(S,exp[i]); i++; break;}
case ")": {
if(! StackEmpty(S)&&GetTop(S)=='(')
{Pop(S,e); i++;}
else state = 0;
break; }
}
void main()
{ Sqstack S;
InitStack(S);
Status matching('(') ;
}
出現的問題都不懂怎么解決 原來是想解決一下()【】符號匹配的問題的
uj5u.com熱心網友回復:
出現什么問題都沒說啊轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/140638.html
標籤:基礎類
