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


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

本文整理汇总了C++中MyStack::peek方法的典型用法代码示例。如果您正苦于以下问题:C++ MyStack::peek方法的具体用法?C++ MyStack::peek怎么用?C++ MyStack::peek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MyStack的用法示例。


在下文中一共展示了MyStack::peek方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sortStack

// 追加スタック数2
MyStack sortStack(MyStack stack) {
    MyStack ans(10), tmp(10);
    // 最小値を見つける
    while (!stack.isEmpty()) {
        int min = stack.peek();
        while (!stack.isEmpty()) {
            int t = stack.peek();
            stack.pop();
            if (t <= min) {
                min = t;
            }
            tmp.push(t);
        }

        // 最小値を入れる
        while (!tmp.isEmpty()) {
            if (tmp.peek() == min) {
                ans.push(tmp.peek());
            } else {
                stack.push(tmp.peek());
            }
            tmp.pop();
        }
    }
    return ans;
}
开发者ID:keigo-brook,项目名称:BookSutras,代码行数:27,代码来源:q5_sort_stack.cpp

示例2: sortTokenByStacks

/* Function: sortTokenByStacks()
 * Usage: is called by formulaStringScanning() for single token;
 * -----------------------------------------------------------------------------------------//
 * Sort this token through the stacks. If token is number - push it to stackNumbers.
 * If token is valid operator token - process it due to Shunting-Yard conditions.
 *
 * @param token             Current token in formula string
 * @param stackNumbers      Stack of number values for current recursion
 * @param stackOperators    Stack of operators for current recursion */
void sortTokenByStacks(string token,
                       MyStack<double> &stackNumbers,
                       MyStack<string> &stackOperators) {
    if(stringIsDouble(token)) { //Token is number
        double num = stringToDouble(token);
        stackNumbers.push(num);//Just save token to stack
    } else { // Token is operator
        /* Main operators process */
        if(stackOperators.isEmpty()) { //Empty - push there without conditions
            stackOperators.push(token);
        } else { //If there are some operators in stack
            string topOper = stackOperators.peek();//Get top operator
            if(getOperPrecedence(topOper) < getOperPrecedence(token)) {
                /* Top operator precednce is
                 * weaker then this token operator - just save this token */
                stackOperators.push(token);
            } else {
                /* Top operator precednce is higher - evaluate two top numbers
                 * with top operator, and sort current token again */
                if(!failFlag) { //If there some fails - break this function
                    /* Main calculation for top numbers and top operator  */
                    twoNumsProcess(stackNumbers, stackOperators);
                    /* Call sorting again to process current token operator  */
                    sortTokenByStacks(token, stackNumbers, stackOperators);
                }
            }
        }
    }
}
开发者ID:ekuryatenko,项目名称:cs-b-assignment3_Calculator,代码行数:38,代码来源:Calculator.cpp

示例3: Driver

void Driver(MyStack<T> &listObject)
{
	T max;
	cout << "Welcome to MyStack , Lets Get you started \n\n ";
	cout << "Ok , Lets get one thing straight how big must the Stack be : ";
	cin >> max;
	cout << "\n\nThank you ... Ready Steady Go .. \n\n";
	//instruc();
	int choice;
	T value;
	
	listObject.setMax(max);
		do
		{
			instruc();
			cin >> choice;

			switch (choice)
			{
			case 1:
				cout << "Enter Your Value : ";
				cin >> value;
				listObject.push(value);
				system("cls");
				listObject.peek();
				break;
			case 2:

				listObject.pop(value);
				system("cls");
				listObject.peek();
				
				break;
			}


		} while (choice < 3);


}
开发者ID:mrmakhura,项目名称:Tut4-MyStack,代码行数:40,代码来源:MyStackmain.cpp

示例4: sortStack1

// 追加スタック数1
MyStack sortStack1(MyStack stack) {
    MyStack ans(10);
    while(!stack.isEmpty()) {
        int t = stack.peek(); stack.pop();
        /// 要素がansのtopより小さい間,ansからstackに戻す
        while (!ans.isEmpty() && ans.peek() < t) {
            stack.push(ans.peek());
            ans.pop();
        }
        ans.push(t);
    }

    return ans;
}
开发者ID:keigo-brook,项目名称:BookSutras,代码行数:15,代码来源:q5_sort_stack.cpp

示例5: main

//Driver code
int main()
{
    MyStack s;
    s.push(3);
    s.push(5);
    s.getMin();
    s.push(2);
    s.push(1);
    s.getMin();
    s.pop();
    s.getMin();
    s.pop();
    s.peek();

    return 0;
}
开发者ID:dataAlgorithms,项目名称:dataStructure,代码行数:17,代码来源:getMininumStack.cpp


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