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


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

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


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

示例1: push

 void push(int x) {
     if (minStack.empty() || x <= minStack.top())
         minStack.push(x);
     mainStack.push(x);
 }
开发者ID:wxn7,项目名称:Leetcode,代码行数:5,代码来源:155.+minStack.cpp

示例2: main

int main() {
	int t;
	LL a,b,k;
	scanf("%d", &t);
	while(t--) {
		scanf("%s", str);
		int len = strlen(str);
		for(int i = 0; i < len; i++) {
			if(digit(str[i])) {
				k = str[i] - '0';
				i++;
				while(digit(str[i])) {
					k = k*10 + str[i] - '0';
					i++;
				}
				i--;
				num.push(k);
			} else if(str[i] == '+') {
				if(!op.empty()) {
					while(op.top() == '*' || op.top() == '/') {
						char c = op.top();
						op.pop();
						a = num.top();
						num.pop();
						b = num.top();
						num.pop();
						if(c == '*') {
							num.push(a*b);
						} else if(c == '/'){
							num.push(b/a);
						}	
					}
				}
				op.push(str[i]);		
			} else if(str[i] == '-') {
				if(!op.empty()) {
					while(op.top() == '*' || op.top() == '/') {
						char c = op.top();
						op.pop();
						a = num.top();
						num.pop();
						b = num.top();
						num.pop();
						if(c == '*') {
							num.push(a*b);
						} else if(c == '/'){
							num.push(b/a);
						}	
					}										
				}
	
				op.push(str[i]);		
			} else if(str[i] == '*') {
				op.push(str[i]);
			} else if(str[i] == '/') {
				op.push(str[i]);
			}

		}
	}
	while(!op.empty()) {
		char c = op.top();
		op.pop();
		a = num.top();
		num.pop();
		b = num.top();
		num.pop();
		if(c == '+') {
			num.push(a+b);
		} else if(c == '-') {
			num.push(b-a);
		} else if(c == '*') {
			num.push(a*b);
		} else {
			num.push(b/a);			
		}
	}
	printf("%lld\n", num.top());
}
开发者ID:JetMuffin,项目名称:algorithm,代码行数:79,代码来源:C.cpp

示例3: calculateEdgeBetweennessRandom

//-------------------------------------------------------------------
//Method to calculate the Random Walk edge Betweenness of the input graph
//-------------------------------------------------------------------
void calculateEdgeBetweennessRandom() {

    //--- Community detection...
    int nCommunity    = 0;

    for(int i=1; i<n.size(); i++) {
        n[i].c = 0;
        n[i].v = 0;
        n[i].w = 0;
    }

    for(int i=1; i<n.size(); i++) {

        for(int j=1; j<n.size(); j++)
            n[j].v = 0;

        node startNode  = n[i];
        node_dist.push( startNode.k );

        visitedNodes(startNode.k);

        //--- Communities in Network
        bool newCommunity = false;
        if( n[startNode.k].c == 0) {
            nCommunity  += 1;
            newCommunity = true;
        }

        while( !node_dist.empty() ) {

            int _key = node_dist.top();
            node_dist.pop();

            if(newCommunity)
                n[_key].c = nCommunity;

        }

    }

    int com_max_old = com_max;
    com_max         = 0;
    for(int i=1; i<n.size(); i++) {
        if( n[i].c > com_max )
            com_max = n[i].c;
    }

    //--- Update the matrices
    upDateMatrices();

    vector<node> startNodes;

    for(int c=1; c<com_max+1; c++) {

        //--- Setup the sub-matrices...
        startNodes.clear();

        //--- Get the sub-matrices
        getSubMatrix(c, startNodes);

        //--- Take a random walk within the network,
        //--- and calculate the edge betweenness scores...
        calculateRandomWalk(c, startNodes);

    }


}
开发者ID:hmipakchi,项目名称:FinalYearProject,代码行数:71,代码来源:communityDetection.C

示例4: insertR


//.........这里部分代码省略.........
        else { // split the $node
            //TODO:
            // check whether other threads are manipulating the node by
            // using the $thread_on in each node. And wait to lock the node. 
            pthread_mutex_lock(&node->mutex);
            while (node->thread_on ^ (0x01 << tid)) {
                //!!!careful: if it needs to reset the $thread_on 
                // and set it after condition wait.
                node->thread_on ^= 0x01 << tid; //!? right or wrong?
                pthread_cond_wait(&node->is_going_splitting, &node->mutex);
                node->thread_on |= 0x01 << tid; //!? right or wrong?
            }
            // start to split; reorganize first
            node->reorganize_bit |= 0x01;
            reorganize(node);
            node->reorganize_bit &= 0x00;

            Node u = node;
            Node v = createNode(1); // 1 => is leaf;
            Node r_subtree = r_child_of_key;
            int median = splitLeaf(u, v);
            int elem = key;
            int finish = 0;
            if (u == root) {
                root = createNode(0);
                root->keys[0] = median;
                root->organized_keys++;
                root->child[0] = u;
                root->child[1] = v;
                finish = 1;
            }
            else {
                elem = median;
                r_subtree = v;
                u = (Node) path_stack->top(path_stack)->data;
                path_stack->pop(path_stack);
            }
            pthread_mutex_unlock(&node->mutex);

            while (/*!path_stack->is_empty() && */!finish) {
                if (u->organized_keys < (order - 1)) {
                    insertElem(elem, r_subtree, u);
                    finish = 1;
                }
                else {
                    v = createNode(0);
                    median = splitNonleaf(elem, r_subtree, u, v);

                    if (u == root) {
                        root = createNode(0);
                        root->keys[0] = median;
                        root->organized_keys++;
                        root->child[0] = u;
                        root->child[1] = v;
                        finish = 1;
                    }
                    else {
                        pthread_mutex_unlock(&u->mutex);
                        elem = median;
                        r_subtree = v;
                        u = (Node) path_stack->top(path_stack)->data;
                        path_stack->pop(path_stack);
                    }
                }
            }
            pthread_mutex_unlock(&u->mutex);
        }

        pthread_mutex_lock(&node->mutex);
        node->thread_on ^= 0x01 << tid;
        pthread_cond_signal(&node->is_going_splitting);
        pthread_mutex_unlock(&node->mutex);
    }
    else { // lock this node, and follow child[i]
        pthread_mutex_lock(&node->mutex);

        // if current node is safe, then release all ancestors.
        if (node->organized_keys < (order - 1)) {
            while (!path_stack->is_empty()) {
                pthread_mutex_unlock(&((Node) path_stack->top(path_stack)->data)->mutex);
                path_stack->pop(path_stack);
            }
        }

        // search in organized region (linear)
        int i;
        for (i = 0; i < node->organized_keys; ++i) {
            if (key == node->keys[i])
                return 0;
            else if (key < node->keys[i])
                break;
        }
        // key is between [i - 1] and [i]; follow child[i]

        struct stack_node_struct stack_node;
        stack_node.data = node;
        path_stack->push(path_stack, &stack_node);
        insertR(key, r_child_of_key, node->child[i], path_stack);
    }
}
开发者ID:chenweiyj,项目名称:numa-effect,代码行数:101,代码来源:lock-free-btree.c

示例5: push

 void push(int x) {
     m_list.push(x);
     m_min.push(m_min.empty() ? x : min(m_min.top(), x));
 }
开发者ID:tsenmu,项目名称:leetcode,代码行数:4,代码来源:solution-0.cpp

示例6: generate_moves

void King::generate_moves(Board game, int x_cor, int y_cor, stack<int> &x_cans, stack<int> &y_cans) {
    //up-right direction
    int i=y_cor+1;
    int j=x_cor+1;
    if(i<8 && j<8){
        if (game.board[i][j]!=0){
            if (game.board[i][j]->isBlack!=game.board[y_cor][x_cor]->isBlack){
                x_cans.push(j);
                y_cans.push(i);
            }
        }
        else {
            x_cans.push(j);
            y_cans.push(i);
        }
    }
    //down right direction
    i=y_cor-1;
    j=x_cor+1;
    if (i>=0 && j<8){
        if (game.board[i][j]!=0){
            if (game.board[i][j]->isBlack!=game.board[y_cor][x_cor]->isBlack){
                x_cans.push(j);
                y_cans.push(i);
            }
        }
        else {
            x_cans.push(j);
            y_cans.push(i);
        }
    }
    //up left direction
    i=y_cor+1;
    j=x_cor-1;
    if (i<8 && j>=0){
        if (game.board[i][j]!=0){
            if (game.board[i][j]->isBlack!=game.board[y_cor][x_cor]->isBlack){
                x_cans.push(j);
                y_cans.push(i);
            }
        }
        else {
            x_cans.push(j);
            y_cans.push(i);
        }
    }
    //down left direction
    i=y_cor-1;
    j=x_cor-1;
    if (i>=0 && j>=0){
        if (game.board[i][j]!=0){
            if (game.board[i][j]->isBlack!=game.board[y_cor][x_cor]->isBlack){
                x_cans.push(j);
                y_cans.push(i);
            }
        }
        else {
            x_cans.push(j);
            y_cans.push(i);
        }
    }
    //up direction
    i=y_cor+1;
    if (i<8){
        if (game.board[i][x_cor]!=0){
            if (game.board[i][x_cor]->isBlack!=game.board[y_cor][x_cor]->isBlack){
                x_cans.push(x_cor);
                y_cans.push(i);
            }
        }
        else {
            x_cans.push(x_cor);
            y_cans.push(i);
        }
    }
    //down direction
    i=y_cor-1;
    if (i>=0){
        if (game.board[i][x_cor]!=0){
            if (game.board[i][x_cor]->isBlack!=game.board[y_cor][x_cor]->isBlack){
                x_cans.push(x_cor);
                y_cans.push(i);
            }
        }
        else {
            x_cans.push(x_cor);
            y_cans.push(i);
        }
    }
    //right direction
    i=x_cor+1;
    if (i<8){
        if (game.board[y_cor][i]!=0){
            if (game.board[y_cor][i]->isBlack!=game.board[y_cor][x_cor]->isBlack){
                x_cans.push(i);
                y_cans.push(y_cor);
            }
        }
        else {
            x_cans.push(i);
//.........这里部分代码省略.........
开发者ID:ENC-Engineering,项目名称:Chess_Project,代码行数:101,代码来源:chess_pieces.cpp

示例7: decodeBlock

NativeBlockPtr decodeBlock( ExecutableContainer *c, 
                            ExternalFunctionMap &f,
                            LLVMByteDecoder     &d,
                            stack<VA>           &blockChildren,
                            VA                  e,
                            stack<VA>           &funcs,
                            raw_ostream         &out)
{
  NativeBlockPtr  B = NativeBlockPtr(new NativeBlock(e, d.getPrinter()));
  VA              curAddr = e;
  bool            has_follow = true;

out << "Processing block: " << B->get_name() << "\n";
do
  {
    InstPtr I = d.getInstFromBuff(curAddr, c);

    //I, if a terminator, will have true and false targets 
    //filled in. I could be an indirect branch of some kind,
    //we will deal with that here. we will also deal with the 
    //instruction if it is a data instruction with relocation
   
    out << to_string<VA>(I->get_loc(), hex) << ":";
    out << I->printInst() << "\n";

    if(I->get_tr() != 0) {
      B->add_follow(I->get_tr());
      has_follow = false;
      out << "Adding block: " << to_string<VA>(I->get_tr(), hex) << "\n";
      blockChildren.push(I->get_tr());
    }

    if(I->get_fa() != 0) {
      B->add_follow(I->get_fa());
      has_follow = false;
      out << "Adding block: " << to_string<VA>(I->get_fa(), hex) << "\n";
      blockChildren.push(I->get_fa());
    }

    if(I->terminator()) {
      has_follow = false;
    }

    //do we need to add a data reference to this instruction?
    //again, because there is no offset information in the 
    //instruction decoder, for now we just ask if every addr
    //in the inst is relocated
    for(uint32_t i = 0; i < I->get_len(); i++) {
      VA addrInInst = curAddr+i;
      if(c->is_addr_relocated(addrInInst)) {
        VA  addr = 0;
        std::string has_imp;

        // this instruction has a relocation
        // save the relocation offset for later
        I->set_reloc_offset(i);

        //get the offset for this address
        //add it as a data offset to the instruction
        if (c->find_import_name(addrInInst, has_imp) )  {

            if(f.is_data(has_imp)) 
            {
                ExternalDataRefPtr data_p = makeExtDataRefFromString(has_imp, f);
                out << "Adding external data ref: " << has_imp << "\n";
                I->set_ext_data_ref(data_p);
            }
            else
            {
                ExternalCodeRefPtr code_p = makeExtCodeRefFromString(has_imp, f);
                LASSERT(code_p, "Failed to get ext call from map for symbol: "+has_imp);
                //maybe, this call doesn't return, in which case, 
                //we should kill the decoding of this flow
                if(code_p->getReturnType() == ExternalCodeRef::NoReturn) {
                    has_follow = false;
                }
                out << "Adding external code ref: " << has_imp << "\n";
                I->set_ext_call_target(code_p);
            }
                    
        } else if(c->relocate_addr(addrInInst, addr)) {
            bool can_ref_code = canInstructionReferenceCode(I);
            bool is_reloc_code = isAddrOfType(c, addr, ExecutableContainer::CodeSection);
            bool is_reloc_data = isAddrOfType(c, addr, ExecutableContainer::DataSection);
            unsigned opc = I->get_inst().getOpcode();

            if(isBranchViaMemory(I)) {
                out << "Detect branch via memory, relocation handled later\n";      
            }
            // this instruction can reference code and does
            // reference code
            // so we assume the code points to a function
            else if( can_ref_code && is_reloc_code ) {
                list<VA> new_funcs;
                if(dataInCodeHeuristic(c, I, addr, new_funcs)) {
                    // add new functions to our functions list
                    for(list<VA>::const_iterator nfi = new_funcs.begin();
                            nfi != new_funcs.end();
                            nfi++)
                    {
//.........这里部分代码省略.........
开发者ID:andrnag,项目名称:mcsema,代码行数:101,代码来源:cfg_recover.cpp

示例8: startEntryEvent

void startEntryEvent(int id)
{
  dprintf("---------> starting Entry Event with id: %d\n", id);

  if ((id == -1) || (events[id] == NULL))
    {
      dprintf("-------> create event with id: %d\n", id);
      //sprintf(name, "Event %d", id);
      if (id == -1)
	{ /*
	    char *name = "dummy_thread_ep";
	    dprintf(" ------> creating event: %s\n", name);
	    TAU_PROFILER_CREATE(events[id], name, "", TAU_DEFAULT);
	    dprintf("timer created.\n");
	    eventStack.push(events[id]);
	    dprintf(" ------> starting event: %s\n", (char*) name);
	    TAU_PROFILER_START(eventStack.top());*/
	  //exclude dummy event
	  dprintf("------> excluding dummy function");
	  eventStack.push(EXCLUDED);
	}
      else
	{
	  //string check("doFFT(RSFFTMsg* impl_msg)");
	  //string name_s(_entryTable[id]->name);
	  //printf("checking name4: %s", _entryTable[id]->name);
	  //if (check.compare(name_s) != 0)
	  //{
	  char name [500];
	  sprintf(name, "%s::%s::%d", _chareTable[_entryTable[id]->chareIdx]->name,
		  _entryTable[id]->name, id);
	  //should this fuction be excluded from instrumentation?
	  if (!instrumentEntity(name))
	    {
	      //exclude function.
	      dprintf("------> excluding function %s\n", name);
	      events[id] = EXCLUDED;
	      eventStack.push(events[id]);
	    }
	  else
	    {
	      dprintf(" ------> creating event: %s\n", name);
	      TAU_PROFILER_CREATE(events[id], name, "", TAU_DEFAULT);
	      dprintf("timer created.\n");
	      eventStack.push(events[id]);
	      dprintf("starting event\n");
	      dprintf(" ------> starting event: %s\n", (char*) name);
	      TAU_PROFILER_START(eventStack.top());
	    }
	  dprintf("done.\n");
	}
    }
  else
    {
      eventStack.push(events[id]);
      if (events[id] != EXCLUDED)
	{
	  TAU_PROFILER_START(eventStack.top());
	}
    }
}
开发者ID:varunbhatia16,项目名称:DIC_project,代码行数:61,代码来源:trace-Tau.C

示例9: join

		void join(double val)
		{
			in.push(val);
		}
开发者ID:cyveros,项目名称:minidc,代码行数:4,代码来源:minidc.cpp

示例10: Push

inline void Push(int x)
{
    mark[x]=1;
    ins[x]=1;
    s.push(x);
}
开发者ID:szefany,项目名称:training,代码行数:6,代码来源:J.cpp

示例11: push

    // Push element x to the back of queue.
    void push(int x) {
		S1.push(x);
    }
开发者ID:glf3,项目名称:LeetCode,代码行数:4,代码来源:Implement+Queue+using+Stacks.cpp

示例12: Work

void Work(string str)
{
	int i,Error = 0;
	string tmp = "";
	for(i = str.size()-1; i >= 0; i--)
	{
		if(str[i] == ' ')
		{
			if(tmp == "+")		opStack.push('+');
			else if(tmp == "-")	opStack.push('-');	
			else if(tmp == "*")	opStack.push('*');
			else if(tmp == "/")	opStack.push('/');
			else				valStack.push(Convert(tmp));	
			tmp = "";
			while(valStack.size() >= 2 && opStack.size() >= 1)
			{//进行运算 
				double a = valStack.top(); valStack.pop();
				double b = valStack.top(); valStack.pop();
				char op  = opStack.top();  opStack.pop();
				if(op == '+')	 	valStack.push(a+b);
				else if(op == '-') 	valStack.push(a-b);
				else if(op == '*') 	valStack.push(a*b);
				else if(op == '/')
				{
					if(b==0) 
					{
						Error = 1;
						break;
					}
					else valStack.push(a/b);
				} 	
			}
		}	
		else
		{
			tmp += str[i];
		}
	}
	
	if(Error == 1)
	{
		puts("ERROR"); return;
	}
	
	if(tmp == "+")		opStack.push('+');
	else if(tmp == "-")	opStack.push('-');	
	else if(tmp == "*")	opStack.push('*');
	else if(tmp == "/")	opStack.push('/');
	else				valStack.push(Convert(tmp));	
	tmp = "";
	while(valStack.size() >= 2 && opStack.size() >= 1)
	{//进行运算 
		double a = valStack.top(); valStack.pop();
		double b = valStack.top(); valStack.pop();
		char op  = opStack.top();  opStack.pop();
		if(op == '+')	 	valStack.push(a+b);
		else if(op == '-') 	valStack.push(a-b);
		else if(op == '*') 	valStack.push(a*b);
		else if(op == '/')
		{
			if(b==0) 
			{
				Error = 1;
				break;
			}
			else valStack.push(a/b);
		}
	}
	
	if(Error == 1)
	{
		puts("ERROR"); return;
	}
	
	if(opStack.size() == 0 && valStack.size() == 1)
	{
		printf("%.1lf\n", valStack.top());
	}
	else
	{
		puts("ERROR");
	}
}
开发者ID:751816957,项目名称:PAT,代码行数:83,代码来源:3-07_求前缀表达式.cpp

示例13: stackQuery

void XapianEngine::stackQuery(const QueryProperties &queryProps,
	stack<Xapian::Query> &queryStack, const string &stemLanguage, bool followOperators)
{
	Xapian::Query::op queryOp = Xapian::Query::OP_OR;
	string term;

	// Get the terms to AND together
	if (queryProps.getAndWords().empty() == false)
	{
		vector<string> andTerms;

		if (extractWords(queryProps.getAndWords(), stemLanguage, andTerms) == true)
		{
#ifdef DEBUG
			cout << "XapianEngine::stackQuery: OP_AND " << andTerms.size() << endl;
#endif
			if (followOperators == true)
			{
				queryOp = Xapian::Query::OP_AND;
			}
			queryStack.push(Xapian::Query(queryOp, andTerms.begin(), andTerms.end()));
		}
	}

	// Get the terms of the phrase
	if (queryProps.getPhrase().empty() == false)
	{
		vector<string> phraseTerms;

		if (extractWords(queryProps.getPhrase(), stemLanguage, phraseTerms) == true)
		{
#ifdef DEBUG
			cout << "XapianEngine::stackQuery: OP_PHRASE " << phraseTerms.size() << endl;
#endif
			if (followOperators == true)
			{
				queryOp = Xapian::Query::OP_PHRASE;
			}
			queryStack.push(Xapian::Query(queryOp, phraseTerms.begin(), phraseTerms.end()));
		}
	}

	// Get the terms to OR together
	if (queryProps.getAnyWords().empty() == false)
	{
		vector<string> orTerms;

		if (extractWords(queryProps.getAnyWords(), stemLanguage, orTerms) == true)
		{
#ifdef DEBUG
			cout << "XapianEngine::stackQuery: OP_OR " << orTerms.size() << endl;
#endif
			if (followOperators == true)
			{
				queryOp = Xapian::Query::OP_OR;
			}
			queryStack.push(Xapian::Query(queryOp, orTerms.begin(), orTerms.end()));
		}
	}

	// Get the terms to NOT together
	if (queryProps.getNotWords().empty() == false)
	{
		vector<string> notTerms;

		if (extractWords(queryProps.getNotWords(), stemLanguage, notTerms) == true)
		{
#ifdef DEBUG
			cout << "XapianEngine::stackQuery: OP_AND_NOT " << notTerms.size() << endl;
#endif
			// We need something to AND_NOT these terms against
			// Not following the operator would make us return documents
			// that have terms the user isn't interested in
			Xapian::Query notQuery(Xapian::Query::OP_AND, notTerms.begin(), notTerms.end());
			if (queryStack.empty() == false)
			{
				Xapian::Query topQuery = queryStack.top();
				queryStack.pop();

				queryStack.push(Xapian::Query(Xapian::Query::OP_AND_NOT, topQuery, notQuery));
			}
		}
	}

	// Get the host name filter
	if (queryProps.getHostFilter().empty() == false)
	{
		vector<string> hostTerms;

		term = "H";
		term += StringManip::toLowerCase(queryProps.getHostFilter());
		hostTerms.push_back(term);
		if (followOperators == true)
		{
			queryOp = Xapian::Query::OP_AND;
		}
		queryStack.push(Xapian::Query(queryOp, hostTerms.begin(), hostTerms.end()));
	}

	// Get the file name filter
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:pinot-svn,代码行数:101,代码来源:XapianEngine.cpp

示例14: push

 void push(int a){
     lock_guard<mutex> lock(mx);
     st.push(a);    
 }
开发者ID:CCJY,项目名称:coliru,代码行数:4,代码来源:main.cpp

示例15: dfs

void dfs (int u) {
	if (u == ((1<<n)-1)) return;
	stk.push(shoot[u]);
	dfs(father[u]);
}
开发者ID:facug91,项目名称:OJ-Solutions,代码行数:5,代码来源:Jumpingmonkey.cpp


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