Ejemplo n.º 1
0
int rodaSolucao()
{
	int i, j, first;
	int retorno;
	Input teste;
	qtdThreads = 0;
	
	for(i = 0; i<N_THR; i++)
	{
		addToStack(i);
		interesse[i] = -1;
	}

	first = getFromStack();
	
	for(i = 0; i< 9; i++)
			for(j = 0; j< 9; j++)
				scanf("%c ",&thrInput[first].matriz[i][j]);
	
	thrInput[first].x = 0;
	thrInput[first].y = 0;
	thrInput[first].id = first;
	
	pthread_create(&threadPool[first],NULL,f_thread,&thrInput[first]);
	while(freeCount < N_THR);
	//	printf("|%d|",freeCount);
	
	//printf("total:%d",qtdThreads);
	
	if(flag_solucao == 0)
		printf("Sudoku invalido.\n");
	
	return 0;
}
Ejemplo n.º 2
0
static void XMLCALL characterDataHandler(void* userData, const char* s, int len) {
    XML_Parser parser = reinterpret_cast<XML_Parser>(userData);
    Stack* stack = reinterpret_cast<Stack*>(XML_GetUserData(parser));

    if (!s || len <= 0) {
        return;
    }

    // See if we can just append the text to a previous text node.
    if (!stack->nodeStack.empty()) {
        Node* currentParent = stack->nodeStack.top();
        if (!currentParent->children.empty()) {
            Node* lastChild = currentParent->children.back().get();
            if (lastChild->type == NodeType::kText) {
                Text* text = static_cast<Text*>(lastChild);
                text->text += util::utf8ToUtf16(StringPiece(s, len));
                return;
            }
        }
    }

    std::unique_ptr<Text> text = util::make_unique<Text>();
    text->text = util::utf8ToUtf16(StringPiece(s, len));
    addToStack(stack, parser, std::move(text));
}
Ejemplo n.º 3
0
int main(void){
	Stack * stack;
	char * tempValue;
	int i;
	
	printf("\nCreating a new Stack");
	
	stack = createStack("1");
	tempValue = malloc(sizeof(char) * 128);
	
	for(i=2;i<101;i++){
		sprintf(tempValue,"%d",i);
		stack = addToStack(tempValue,stack);
	}
	
	printf("\nThe value of the element on top of the stack is: %s",getTopValue(stack));
	printf("\nPrinting the stack");
	printStack(stack);
	printf("\nRemoving the top element of the stack, and printing again");
	stack = removeFromTop(stack);
	printStack(stack);
	printf("\nThe value of the element on top of the stack is: %s",getTopValue(stack));
	printf("\nDeleting the stack, and then printing again");
	stack = deleteStack(stack);
	printStack(stack);
	printf("\nThe value of the element on top of the stack is: %s",getTopValue(stack));
	printf("\nAttempting to delete an empty stack");
	stack = deleteStack(stack);
	printf("\nAttempting to remove the top element of an empty stack");
	stack = removeFromTop(stack);
	printf("\nAttempting to add an element to an empty stack");
	stack = addToStack("1",stack);	
	printf("\nThe value of the element on top of the stack is: %s",getTopValue(stack));
	printf("\nPrinting the stack");
	printStack(stack);
	printf("\nAdding an element with an empty value");
	stack = addToStack(NULL,stack);
	printf("\nThe value of the element on top of the stack is: %s",getTopValue(stack));
	printf("\nPrinting the stack");	
	printStack(stack);
	printf("\n");
	
	return(0);
}
Ejemplo n.º 4
0
static void XMLCALL startNamespaceHandler(void* userData, const char* prefix, const char* uri) {
    XML_Parser parser = reinterpret_cast<XML_Parser>(userData);
    Stack* stack = reinterpret_cast<Stack*>(XML_GetUserData(parser));

    std::unique_ptr<Namespace> ns = util::make_unique<Namespace>();
    if (prefix) {
        ns->namespacePrefix = util::utf8ToUtf16(prefix);
    }

    if (uri) {
        ns->namespaceUri = util::utf8ToUtf16(uri);
    }

    addToStack(stack, parser, std::move(ns));
}
Ejemplo n.º 5
0
static void XMLCALL startElementHandler(void* userData, const char* name, const char** attrs) {
    XML_Parser parser = reinterpret_cast<XML_Parser>(userData);
    Stack* stack = reinterpret_cast<Stack*>(XML_GetUserData(parser));

    std::unique_ptr<Element> el = util::make_unique<Element>();
    splitName(name, &el->namespaceUri, &el->name);

    while (*attrs) {
        Attribute attribute;
        splitName(*attrs++, &attribute.namespaceUri, &attribute.name);
        attribute.value = util::utf8ToUtf16(*attrs++);

        // Insert in sorted order.
        auto iter = std::lower_bound(el->attributes.begin(), el->attributes.end(), attribute,
                                     lessAttribute);
        el->attributes.insert(iter, std::move(attribute));
    }

    el->comment = std::move(stack->pendingComment);
    addToStack(stack, parser, std::move(el));
}
Ejemplo n.º 6
0
void* f_thread(void* p)
{
	Input *inp = p;
	int id = inp->id;
	void *resp = backtrack_thread(id);
	
	// !INICIO DA ZONA CRITICA!
	int f,k;
	for (f = 0; f < N_THR-1; f++) {
		interesse[id] = f;
		ultimo[f] = id; 
		for (k = 0; k < N_THR && ultimo[f] == id; k++)
			if (k != id)
			   while (f <= interesse[k] && ultimo[f] == id);  
	}
	addToStack(inp->id);
	interesse[id] = -1;
	// !FIM DA ZONA CRITICA!
	pthread_exit(0);	
	return (void*)	55;
}
Ejemplo n.º 7
0
void drawB(float x, float y, float z){
  if(Aisclippingwindow && (posB == 0 || posB == 1))
  	return;
  addToStack();
    translate(x, y, z);
    if(Aisclippingwindow)
    {
      if(posB == 2)
      {
        translate(-0.5, -3.0, 0.0);
        Bpart(RED);
      }
      else if(posB == 3)
      {
        translate(-0.5, 0.0, 0.0);
        Bpart(BLUE);
      }
          else if(posB == 4)
      {
        translate(-0.5, 3.0, 0.0);
        Bpart(GREEN);
      }
    }
    else
    {
      translate(-0.5, -3.0, 0.0);
      Bpart(RED);
      translate(0.0, 3.0, 0.0);
      Bpart(BLUE);
      translate(0.0, 3.0, 0.0);
      Bpart(GREEN);
      translate(0.5, 1.5, 0.0);
      Bgreencap;
      translate(0.0, -9.0, 0.0);
      Bredcap;
    }
  removeFromStack();
}
Ejemplo n.º 8
0
void drawA(float x, float y, float z){
  addToStack();
    translate(x, y, z);
    addToStack();
      translate(2.5, 0.0, 0.0);
      addRectangle(vertex(0.0, 1.5, 2.5), vertex(0.0, -1.5, 2.5), YELLOW);
      translate(-5.0, 0.0, 0.0);
      addRectangle(vertex(0.0, -1.5, 2.5), vertex(0.0, 1.5, 2.5), YELLOW);
    removeFromStack();
    addToStack();
      translate(0.5, 0.0, 0.0);
      addRectangle(vertex(0.0, -1.5, 0.5), vertex(0.0, 1.5, 0.5), GREY);
      translate(-1.0, 0.0, 0.0);
      addRectangle(vertex(0.0, 1.5, 0.5), vertex(0.0, -1.5, 0.5), GREY);
    removeFromStack();
    addToStack();
      translate(0.0, 0.0, 2.5);
      addRectangle(vertex(-2.5, 1.5, 0.0), vertex(-2.5, -1.5, 0.0), YELLOW);
      translate(0.0, 0.0, -5.0);
      addRectangle(vertex(-2.5, -1.5, 0.0), vertex(-2.5, 1.5, 0.0), YELLOW);
    removeFromStack();
    addToStack();
      translate(0.0, 0.0, 0.5);
      addRectangle(vertex(-0.5, -1.5, 0.0), vertex(-0.5, 1.5, 0.0), GREY);
      translate(0.0, 0.0, -1.0);
      addRectangle(vertex(-0.5, 1.5, 0.0), vertex(-0.5, -1.5, 0.0), GREY);
    removeFromStack();
    addToStack();
      translate(1.5, 1.5, 0.0);
      addRectangle(vertex(-1.0, 0.0, -0.5), vertex(-1.0, 0.0, 0.5), YELLOW);
      addToStack();
        translate(0.0, -3.0, 0.0);
        addRectangle(vertex(-1.0, 0.0, 0.5), vertex(-1.0, 0.0, -0.5), YELLOW);
      removeFromStack();
      translate(-3.0, 0.0, 0.0);
      addRectangle(vertex(-1.0, 0.0, -0.5), vertex(-1.0, 0.0, 0.5), YELLOW);
      addToStack();
        translate(0.0, -3.0, 0.0);
        addRectangle(vertex(-1.0, 0.0, 0.5), vertex(-1.0, 0.0, -0.5), YELLOW);
      removeFromStack();
    removeFromStack();
    addToStack();
      translate(0.0, 1.5, 1.5);
      addRectangle(vertex(-2.5, 0.0, -1.0), vertex(-2.5, 0.0, 1.0), YELLOW);
      addToStack();
        translate(0.0, -3.0, 0.0);
        addRectangle(vertex(-2.5, 0.0, 1.0), vertex(-2.5, 0.0, -1.0), YELLOW);
      removeFromStack();
      translate(0.0, 0.0, -3.0);
      addRectangle(vertex(-2.5, 0.0, -1.0), vertex(-2.5, 0.0, 1.0), YELLOW);
      addToStack();
        translate(0.0, -3.0, 0.0);
        addRectangle(vertex(-2.5, 0.0, 1.0), vertex(-2.5, 0.0, -1.0), YELLOW);
      removeFromStack();
    removeFromStack();
  removeFromStack();
}