本文整理汇总了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;
}
示例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);
}
}
}
}
}
示例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);
}
示例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;
}
示例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;
}