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


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

本文整理汇总了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);
}
开发者ID:georgesuperman,项目名称:interview-code,代码行数:16,代码来源:3_4_hanoi_stack.cpp

示例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;
        }

}
开发者ID:cuonngo,项目名称:CS163-DATA-STRUCTURES,代码行数:20,代码来源:main.cpp

示例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);



//.........这里部分代码省略.........
开发者ID:agrimaseth,项目名称:Data-Structures,代码行数:101,代码来源:tbt.cpp


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