Exemplo n.º 1
0
void		calc_loop(t_stack *stack,
			  t_stack_node *node)
{
  t_stack_node	*right;
  t_stack_node	*op;
  int		search;

  search = 1;
  while (search && right != NULL && op != NULL)
    {
      right = node->next;
      op = right->next;
      if (node->type == NPI_TYPE_NUMBER && right->type == NPI_TYPE_NUMBER
	  && op->type == NPI_TYPE_OPERATOR)
	{
	  search = 0;
	  node->value = calc_do(node->value,
				right->value, op);
	  stack_node_destroy(stack, right);
	  stack_node_destroy(stack, op);
	}
      else
	{
	  node = right;
	  right = op;
	  op = op->next;
	}
    }
}
Exemplo n.º 2
0
Arquivo: stack.c Projeto: ppenna/mylib
/**
 * @brief Pops an object from a stack.
 * 
 * @details Pops the top object from the stack pointed to by @p s.
 * 
 * @param s Stack where the object should be popped from.
 * 
 * @returns The object on the top of the stack.
 */
object_t stack_pop(struct stack *s)
{
	object_t obj;       /* Object in top node. */
	struct snode *node; /* Top node.           */
	
	/* Sanity check. */
	assert(s != NULL);
	assert(!stack_empty(s));
	
	/* Unlink node. */
	node = s->head.next;
	s->head.next = node->next;
	s->size--;
	
	/* Get object. */
	obj = node->obj;
	stack_node_destroy(node);
	
	return (obj);
}