資料結構 棧的應用

2021-09-05 19:26:08 字數 1337 閱讀 3685

要求:首先將運算元棧opnd設為空棧,而將'#'作為運算子棧opter的棧底元素,這樣的目的是判斷表示式是否求值完畢;(2)依次讀入表示式的每個字元,表示式須以'#'結尾,若是運算元則入棧opnd,若是運算子,則將此運算子c與opter的棧頂元素top比較優先順序後執行相應的操作,具體操作如下:(i)若top的優先順序小於c,即top這一步目的是進行括號操作。

#include #include #define stack_init_size 100

#define stackincrement 10

typedef structsqstack;

typedef structsqstacknum;

int initstack(sqstack *s)

int initstacknum(sqstacknum *s)

char gettop(sqstack s)

int gettopnum(sqstacknum s)

int push(sqstack *s, char e)

*s->top++ = e;

return 1;

}int pushnum(sqstacknum *s, int e)

*s->top++ = e;

return 1;

}int pop(sqstack *s, char *e)

int popnum(sqstacknum *s, int *e)

int operate(int a, char theta, int b)

//printf("no this theta");

//printf("%c^",theta);

}int in(char c)

return 1;

}int getindex(char theta) //獲取theta所對應的索引

return index;

}char getpriority(char theta1, char theta2) //獲取theta1與theta2之間的優先順序

資料結構 棧應用

一 算術表示式的中綴表示 把運算子放在參與運算的兩個運算元中間的算術表示式稱為中綴表示式。例如 2 3 4 6 9 算術表示式中包含了算術運算子和算術量 常量 變數 函式 而運算子之間又存在著優先順序,不能簡單地進行從左到右運算,編譯程式在求值時,不能簡單從左到右運算,必須先算運算級別高的,再算運算...

資料結構 棧的應用

棧是限制插入和刪除只能在乙個位置上進行的表,該位置是表的末端,也叫做棧頂。對棧的操作有進棧和出棧,進棧也叫做插入,出棧也就是刪除最後插入的元素。因此棧也被稱作lifo 後進先出 表。棧通常有兩種實現方式,陣列實現和鍊錶實現。下面是棧的兩個小應用demo 字串逆序 由於棧後進先出的特性,所以棧可以用於...

資料結構 棧的應用

stack.h include include typedef char elemtype typedef struct stackstack,stackptr 初始化棧 void initstack stackptr s 判空 bool stackempty stackptr s 入棧 void ...