目录
栈
1.判断对称字符串
bool symmertry(int str[]) {
int i, e;
SqStack* s;
InitStack(s);
for (i = 0; str[i] != '\0'; i++) {
push(s, str[i]);
}
for (i = 0; str[i] != '\0'; i++) {
pop(s, e);
if (str[i] != e) {
DestroyStack(s);
return false;
}
}
DestroyStack(s);
return true;
}
2.判断进出栈是否符合标准
int Judge(char str[]) {
int i = 0;
int countI;
int countO;
int len;
len = strlen(str);
countI = countO = 0;
for (i = 0; i < len;) {
if (str[i] == 'I') {
countI++;
i++;
}
else {
if (str[i] == 'O') {
countO++;
i++;
if (countO > countI) {
printf("false\n");
return false;
}
}
}
}
if (countI = countO) {
printf("true\n");
return true;
}
}
3.括号匹配问题
bool Match(char exp[], int n) {
int i = 0; char e;
bool match = true;
LinkstNode* s;
InitStack(s);
while (i < n && match) {
if (exp[i] == '(') {
Push(s, exp[i]);
}
else if (exp[i] = ')') {
if (GetTop(s, e) == true)
{
if (e != '(')
match = false;
else
pop(s, e);
}
else
match = false;
}
i++;
}
if (!StackEmpty(s)) {
match = false;
}
DestroyStack(s);
return match;
}
、