当前位置: 首页>>代码示例>>C++>>正文


C++ MyStack::stackEmpty方法代码示例

本文整理汇总了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;
}
开发者ID:syjs10,项目名称:c,代码行数:26,代码来源:demo.cpp

示例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;
}
开发者ID:bevinxing,项目名称:my-bullshit-code,代码行数:60,代码来源:MyStack_match.cpp

示例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;
	}
	
//.........这里部分代码省略.........
开发者ID:CatLittleLazy,项目名称:CLearning,代码行数:101,代码来源:Stack.cpp


注:本文中的MyStack::stackEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。