本文整理汇总了C++中MyStack::stackEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ MyStack::stackEmpty方法的具体用法?C++ MyStack::stackEmpty怎么用?C++ MyStack::stackEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyStack
的用法示例。
在下文中一共展示了MyStack::stackEmpty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (void)
{
MyStack *pStack = new MyStack(5);
pStack->push('a');
pStack->push('e');
pStack->push('i');
pStack->push('o');
pStack->push('u');
//pStack->clearStack();
pStack->stackTraverse(true);
char elem = 0;
pStack->pop(elem);
cout << elem << endl;
pStack->stackTraverse(true);
cout << pStack -> stackLength() << endl;
if(pStack->stackEmpty()){
cout << "栈为空" << endl;
}
if(pStack->stackFull()){
cout << "栈为满" << endl;
}
delete pStack;
pStack = NULL;
return 0;
}
示例2: main
int main(void)
{
MyStack<char> *pStack = new MyStack<char>(20);
MyStack<char> *pNeedStack = new MyStack<char>(20);
char str[] = "[[]>]]";
char isNeeded = 0;
cout << strlen(str) << endl;
for (int i = 0; i < strlen(str); i++)
{
cout << str[i] << endl;
if (str[i] != isNeeded)
{
pStack->push(str[i]);
cout << "push stack: " << str[i] << endl;
switch(str[i]) {
case '[':
if (0 != isNeeded) {
pNeedStack->push(isNeeded);
cout << "push isNeeded: " << isNeeded << endl;
}
isNeeded = ']';
break;
case '(':
if (0 != isNeeded) {
pNeedStack->push(isNeeded);
cout << "push isNeeded: " << isNeeded << endl;
}
isNeeded = ')';
break;
default:
cout << "string is not matched." << endl;
return 0;
break;
}
} else {
char temp = 0;
pStack->pop(temp);
cout << "pop stack: " << temp << endl;
if (!pNeedStack->pop(isNeeded)) {
isNeeded = 0;
}
cout << "pop isNeeded: " << isNeeded << endl;
}
}
if (pStack->stackEmpty()) {
cout << "string is matched" << endl;
} else {
cout << "string is not matched" << endl;
}
delete pStack;
pStack = NULL;
delete pNeedStack;
pNeedStack = NULL;
return 0;
}
示例3: main
int main(void){
MyStack<char> *pStack = new MyStack<char>(30);
MyStack<char> *pNeedStack = new MyStack<char>(30);
char str[] = "[()]]";
char currentNeed = 0;
for(int i = 0; i < strlen(str);i++){
if(str[i]!=currentNeed){
pStack->push(str[i]);
switch(str[i]){
case '[':
if(currentNeed!=0){
pNeedStack->push(currentNeed);
}
currentNeed = ']';
break;
case '(':
if(currentNeed!=0){
pNeedStack->push(currentNeed);
}
currentNeed = ')';
break;
default:
cout<<"×Ö·û´®²»Æ¥Åä"<<endl;
return 0;
}
}else{
char elem;
pStack->pop(elem);
if(!pNeedStack->pop(currentNeed)){
currentNeed = 0;
}
}
}
if(pStack->stackEmpty()){
cout<<"×Ö·û´®Æ¥Åä"<<endl;
}else{
cout<<"×Ö·û´®²»Æ¥Åä"<<endl;
}
delete pStack;
pStack = NULL;
delete pNeedStack;
pNeedStack = NULL;
/*ÊýÖÆת»»
char num[] = "0123456789ABCDEF";
MyStack<int> *pStack = new MyStack<int>(30);
int N = 2016;
int mod = 0;
while(N != 0){
mod = N % OCTONARY;
pStack->push(mod);
N/=OCTONARY;
}
//pStack->stackTraverse(false);
int elem = 0;
while(!pStack->stackEmpty()){
pStack->pop(elem);
cout<<num[elem];
}
delete pStack;
pStack = NULL;
*/
/*
MyStack<char> *pStack = new MyStack<char>(5);
pStack->push('h');
pStack->push('l');
pStack->stackTraverse(true);
//pStack->clearStack();
pStack->stackTraverse(false);
cout<<pStack->stackLength()<<endl;
if(pStack->stackEmpty()){
cout<<"ջΪ¿Õ"<<endl;
}
if(pStack->stackFull()){
cout<<"ջΪÂú"<<endl;
}
//.........这里部分代码省略.........