Example #1
0
 void compute(stack<int>& operands, stack<char>& operators) {
     const int left = operands.top();
     operands.pop();
     const int right = operands.top();
     operands.pop();
     const char op = operators.top();
     operators.pop();
     if (op == '+') {
         operands.emplace(left + right);
     } else if (op == '-') {
         operands.emplace(left - right);
     }
 } 
Example #2
0
 void compute(stack<int>& operands, stack<string>& operators) {
     const int left = operands.top();
     operands.pop();
     const int right = operands.top();
     operands.pop();
     const string op = operators.top();
     operators.pop();
     if (op == "+") {
         operands.emplace(left + right);
     } else if (op == "-") {
         operands.emplace(left - right);
     } else if (op == "*") {
         operands.emplace(left * right);
     } else if (op == "/") {
         operands.emplace(left / right);
     }
 }
Example #3
0
void DFS(GraphVertex* cur, stack<GraphVertex*> &vertex_order) {
  cur->visited = true;
  for (GraphVertex* &next : cur->edges) {
    if (next->visited == false) {
      DFS(next, vertex_order);
    }
  }
  vertex_order.emplace(cur);
}
Example #4
0
static void
entry(const string &type)
{
#ifdef DEBUG
    types.push(type);
    recognition.emplace();
    if (unrecognized.count(type) == 0) {
        unrecognized[type] = set<string>();
    }
#endif
}
    void operator delete(void* pMem)
    {
        lock_guard<mutex> lock{ s_Mutex };

        const int index{
            (static_cast<MyManagedObject*>(pMem)-s_ManagedObjects.data()) /
            static_cast<intptr_t>(sizeof(MyManagedObject)) };
        if (0 <= index && index < static_cast<int>(s_ManagedObjects.size()))
        {
            s_FreeList.emplace(static_cast<unsigned int>(index));
        }
        else
        {
            free(pMem);
        }
    }
Example #6
0
/// Produce \c element_count foos.
void produce(size_t element_count, size_t id_offset, stack& foos)
{
    size_t id = id_offset;

    {
        lock_guard<mutex> _(g_io_mutex);
        cout << this_thread::get_id() << " - produce from ID " << id << endl;
    }

    for (size_t i = 0; i < element_count; ++i) {
        foos.emplace(foo(id++));
    }

    {
        lock_guard<mutex> _(g_io_mutex);
        cout << this_thread::get_id() << " - produced to ID " << id << endl;
    }
}
Example #7
0
void Node::expandNextNode(stack<Node>& fringe)
{
	auto x = get<0>(nextNodeMove);
	auto y = get<1>(nextNodeMove);

	// Has this function call already expanded a node.
	// We need to keep track of this so that we can increment nextNodeMove
	// until it points to the next valid move.
	auto expanded = false;

	for (/* y */; y < 3; ++y)
	{
		for (/* first init x as stored value, then 0 */ ; x < 3; ++x)
		{
			if (state->isFree(x, y))
			{
				if (!expanded)
				{
					// Add child state to the fringe
					auto newBoard = make_unique<GameBoard>(*state);
					auto newMove = make_unique<Move>(x, y);
					newBoard->makeMove(*newMove);
					fringe.emplace(Node{move(newBoard), this,
						move(newMove), depth > 0 ? depth - 1 : 0,
						alpha, beta, !maximizer});
					expanded = true; // Only expand once per function call
				}
				else
				{
					// Save the coordinates of the next free space
					nextNodeMove = decltype(nextNodeMove){ x, y };
					return;
				}
			}
		}
		x = 0; // On a new row, so reset x to 0
	}

	// No more nodes found, so indicate that with an invalid move
	nextNodeMove = decltype(nextNodeMove){ 3, 3 };
}
Example #8
0
 void push(const T &x) {
   s.emplace(x, std::max(x, empty() ? x : s.top().second));
 }
Example #9
0
 void push(int x) {
     int minVal = d_stack.empty() ? x : min(x, d_stack.top().second);
     d_stack.emplace(x, minVal);
 }