本文整理汇总了C++中stack::peek方法的典型用法代码示例。如果您正苦于以下问题:C++ stack::peek方法的具体用法?C++ stack::peek怎么用?C++ stack::peek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stack
的用法示例。
在下文中一共展示了stack::peek方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hanoi
void hanoi(int n, stack& current, stack& dest, stack& buffer) {
// Move plates 1 till n-1 from current to buffer, using dest as buffer
if (n > 1)
hanoi(n - 1, current, buffer, dest);
// Move plate n from current to dest
int v = current.peek();
current.pop();
dest.push(v);
// Move plates 1 till n-1 from buffer to dest, using current as buffer
if (n > 1)
hanoi(n - 1, buffer, dest, current);
}
示例2: output
//a function that i used to minimize the length of the main function
//this function will ask the user to pick a card from the second deck.
//It will also ask for the answer and if the user answered correctly
//then they will gain a point and the card will be discard.
void output(journal_entry & to_move, stack & single, int & score, char * answer2, char answer[])
{
if(single.peek(to_move)) //peek a card on the deck and return the answer as agruments
{
answer2 = to_move.display(); //print out the question and catch the answer
single.pop(); //remove the card from the deck
cin.get(answer,SIZE,'\n'); cin.ignore(SIZE,'\n'); //ask the user for the answer
compare(answer, answer2, score); //check to see if the user answered correctly
}
else
{
cout << "Deck 2 is empty!" << endl; //else if the deck is empty
return;
}
}
示例3: if
void tbt ::create_exp()
{
int i=0;
cout<<"enter the postfix expression";
cin>>post;
char token;
while(post[i]!='\0')
{
token=post[i];
node *root=new node;
root->data=token;
if(isalpha(token))
{
stack1.push(root);
}
else
{
node *t1=stack1.peek();
stack1.pop();
node *t2=stack1.peek();
stack1.pop();
if(t1->left==NULL&&t2->left==NULL)
{
root->left=t2;
root->right=t1;
root->lbit=root->rbit=1;
t2->right=root;
t1->left=root;
t1->lbit=t1->rbit=0;
t2->lbit=t2->rbit=0;
stack1.push(root);
}
else if(t1->left==NULL&&t2->left!=NULL)
{
root->left=t2;
root->right=t1;
root->lbit=root->rbit=1;
t1->left=root;
node*suc2 =new node;
suc2=t2;
while(suc2->right!=NULL)
{
suc2=suc2->right;
}
suc2->right=root;
stack1.push(root);
}
else if(t1->left!=NULL&&t2->left==NULL)
{
root->left=t2;
root->right=t1;
root->lbit=root->rbit=1;
t2->right=root;
node *pre1=new node;
pre1=t1;
while(pre1->left!=NULL)
{
pre1=pre1->left;
}
pre1->left=root;
stack1.push(root);
}
else if(t1->left!=NULL&&t2->left!=NULL)
{
root->left=t2;
root->right=t1;
root->lbit=root->rbit=1;
node*pre1=new node;
pre1 =t1;
while(pre1->left!=NULL)
{
pre1=pre1->left;
}
pre1->left=root;
node *suc2=new node;
suc2=t2;
while(suc2->right!=NULL)
{
suc2=suc2->right;
}
suc2->right=root;
stack1.push(root);
//.........这里部分代码省略.........