Esempio n. 1
0
int bfs(List nodes[], int startNode, int endNode, int numberOfNodes)
{
    Queue queue;
    queue.front = 0;
    queue.rear = 0;

    int dist[numberOfNodes + 1];
    int i = 0;
    for (i = 0; i <= numberOfNodes; i++) {
        dist[i] = -1;
    }

    dist[startNode] = 0;

    offer(&queue, startNode);
    int currentNode, childNode;
    int numOfChildNodes;
    while (!isEmpty(&queue)) {
        currentNode = poll(&queue);
        if (currentNode == endNode)
                return dist[currentNode];
        numOfChildNodes = getSize(&nodes[currentNode]);
        struct Node *temp = nodes[currentNode].first;
        for(i = 1; i <= getSize(&nodes[currentNode]); i++) {
            if (dist[temp->value] >= 0)
                continue;
            offer(&queue, temp->value);
            dist[temp->value] = dist[currentNode] + 1;
            temp = temp->next;
        }
    }   

    return -1;
}
Esempio n. 2
0
void ProfileWidget::populateTable()
{

    ClearTable();
    //TODO: maybe change this table to the following columns:
    //DOC Title
    //Asking Price  //getPending().value(10)
    //Counter Offer //if (column named 'approved' == 1) counterOffer = getPending.value(11) else counterOffer = null
    //Accept
    //Decline
    QSqlQuery getPending = m_user->getPendingDocuments();
    while(getPending.next())
    {
        int rowIndex = m_counterofferTable->rowCount();
        m_counterofferTable->insertRow(rowIndex);
        QString Ask_price(getPending.value(MainDB::ASKINGPRICE).toString());
        QString offer(getPending.value(MainDB::COUNTEROFFER).toString());
        QString title(getPending.value(MainDB::TITLE).toString());
        QString id(getPending.value(MainDB::UID).toString());

        m_counterofferTable->setItem(rowIndex, UID, new QTableWidgetItem(id));
        m_counterofferTable->setItem(rowIndex, TITLE, new QTableWidgetItem(title));
        m_counterofferTable->setItem(rowIndex, ASKINGPRC, new QTableWidgetItem(Ask_price));
        m_counterofferTable->setItem(rowIndex, CO, new QTableWidgetItem(offer));
        m_counterofferTable->setCellWidget(rowIndex, ACCEPT, new QLabel(tr("Accept")));
        m_counterofferTable->setCellWidget(rowIndex, DECLINE, new QLabel(tr("Decline")));
    }
}
Esempio n. 3
0
map<int, offer> firms::set_supply()
{
	map<int, offer> supply;
	for (map<int, firm>::iterator i = _firms.begin(); i != _firms.end(); ++i)
	{
		supply[i->first] = offer((i->second).getprice(), (i->second).getstock());
	}
	return supply;
}
Esempio n. 4
0
// only for dev
int main(int argc, char *argv[])
{

    // call
    QStringList command;

    for(int i=1; i<argc; i++) {
        command.append(QString("%1").arg(argv[i]));
    }

    //    command.append("function");
    //    command.append("my");
    //    command.append("arg_2");
    //    command.append("arg_3");

    qDebug() << "Return: " << offer(command) << endl;

    return 0;
}
Esempio n. 5
0
static void onAccept(struct Event* event, void* arg)
{
	assert(event != NULL && arg != NULL);

#ifdef DEBUG
	printf("accept a connection.\n");
#endif

	Server* server = (Server*)event->arg;
	int sockfd = server->sockfd;
	assert(sockfd >= 0);
	int connfd = tcpAccept(sockfd);
	assert(connfd >= 0);

	int nextId = server->nextId % server->nthreads;
	server->nextId++;
	offer(server->threads[nextId]->queue, connfd);
	int efd = server->threads[nextId]->efd;
	uint64_t count = 1;
	int n = write(efd, &count, sizeof(count));
	assert(n == sizeof(count)); 
}
Esempio n. 6
0
void mst_krushkal(Graph *g) {
    int i, j, k, count = 1;
    PQ *pq;
    UnionFind *uf;
    datatype *d;
    pq = create_PQ(10);
    uf = UF_create(g->vertex, g->size);
    printf("**************\nKrushkals MST\n**************\n");
    
    for(i = 0; i < 10; i++) {
        for(j = i + 1; j < 10; j++) {
            //count = get_edge_keys(g, edge_keys, i, j);
            if(g->edges[i][j] > 0) {
                d = (datatype *) malloc(sizeof(datatype));
                d->key = g->edges[i][j];
                d->v11 = i;
                d->v12 = j;
                d->v21 = j;
                d->v22 = i;
                offer(pq, d);
                free(d);
            }
        }
    }

    while(!is_empty(pq)){
        d = (datatype *) malloc(sizeof(datatype));
        count = take(pq, d);

        if(uf_is_connected(uf, d->v11, d->v12)) continue;
        Union(uf, d->v11, d->v12);
        printf("Edge %d, %d [%d]\n", d->v11, d->v12, d->key);
        free(d);
    }

}
Esempio n. 7
0
// Cron only removes an item when that item REQUESTS to be removed (by setting
// the flag.)
// Once this happens, Cron has full permission to remove it. Thus, this hook is
// forceful. It
// is cron saying, YOU ARE BEING REMOVED. Period. So cleanup whatever you have
// to clean up.
//
// In this case, it removes the corresponding offer from the market.
//
void OTTrade::onRemovalFromCron()
{
    OTCron* cron = GetCron();

    OT_ASSERT(cron != nullptr);

    // If I don't already have an offer on the market, then I will have trouble
    // figuring out
    // my SCALE, which is stored on the Offer. Therefore I will instantiate an
    // offer (since I
    // store the original internally) and I will look up the scale.
    //

    int64_t scale = 1; // todo stop hardcoding.
    int64_t transactionNum = 0;

    if (offer_ != nullptr) {
        if (!marketOffer_.Exists()) {
            otErr
                << "OTTrade::onRemovalFromCron called with nullptr offer_ and "
                   "empty marketOffer_.\n";
            return;
        }

        std::unique_ptr<OTOffer> offer(new OTOffer());

        // Trying to load the offer from the trader's original signed request
        // (So I can use it to lookup the Market ID, so I can see if the offer
        // is
        // already there on the market.)
        if (!offer->LoadContractFromString(marketOffer_)) {
            otErr << "Error loading offer from string in "
                     "OTTrade::onRemovalFromCron\n";
            return;
        }

        scale = offer->GetScale();
        transactionNum = offer->GetTransactionNum();
    }
    else {
        scale = offer_->GetScale();
        transactionNum = offer_->GetTransactionNum();
    }

    OTMarket* market = cron->GetOrCreateMarket(GetInstrumentDefinitionID(),
                                               GetCurrencyID(), scale);

    // Couldn't find (or create) the market.
    //
    if (market == nullptr) {
        otErr << "Unable to find market within requested parameters in "
                 "OTTrade::onRemovalFromCron.\n";
        return;
    }

    //
    // Let's see if the offer is ALREADY allocated and on this market!
    //
    OTOffer* marketOffer = market->GetOffer(transactionNum);

    // The Offer is already on the Market.
    //
    if (marketOffer != nullptr) {
        offer_ = marketOffer;

        offer_->SetTrade(*this);
    }

    market->RemoveOffer(transactionNum);
}
Esempio n. 8
0
int main(){
	int i;
	int root_val;
	char command[20];
	int insert_val;
	int insert_val_queue;
	int delete_val;
	queue* exp_queue;
	node* exp_node;
	node* root=new_node();
	breadth_arr=(int*)malloc(2*sizeof(int));
	breadth_arr_count=0;
	in_arr=(int*)malloc(2*sizeof(int));
	in_count=0;
	pre_arr=(int*)malloc(2*sizeof(int));
	pre_count=0;
	post_arr=(int*)malloc(2*sizeof(int));
	post_count=0;
	printf("to make tree enter root \n");
	scanf("%d",&root_val);
	root->val=root_val;
	printf("enter command, \"exit\" to exit \n");
	while(true){
		printf("$");
		scanf("%s",command);
		if(strcmp(command,exit_command)==0){
			printf("\n");
			break;
		} 
		else if(strcmp(command,insert_command)==0){
			printf(">");
			scanf("%d",&insert_val);
			insert(root,insert_val);
		}
		else if(strcmp(command,inorder_command)==0){
			inorder(root);
			printf("\n");
			for(i=0;i<in_count;i++){
				printf("%d ",in_arr[i]);
			}
			printf("\n");
		}
		else if(strcmp(command,preorder_command)==0){
			preorder(root);
			printf("\n");
			for(i=0;i<pre_count;i++){
				printf("%d ",pre_arr[i]);
			}
			printf("\n");
		}
		else if(strcmp(command,postorder_command)==0){
			postorder(root);
			printf("\n");
			for(i=0;i<post_count;i++){
				printf("%d ",post_arr[i]);
			}
			printf("\n");
		}
		else if(strcmp(command,breadth_first_command)==0){
			breadth_first(root);
			//printf("count: %d\n",breadth_arr_count);
			for(i=0;i<breadth_arr_count;i++){
				printf("%d ",breadth_arr[i]);
			}
			printf("\n");
		}
		else if(strcmp(command,make_queue)==0){
			exp_queue=new_queue();
		}
		else if(strcmp(command,offer_command)==0){
			printf(">");
			scanf("%d",&insert_val_queue);
			exp_node=(node*)malloc(sizeof(node));
			exp_node->val=insert_val_queue;
			exp_node->left=NULL;
			exp_node->right=NULL;
			offer(exp_node,exp_queue);
		}
		else if(strcmp(command,poll_command)==0){
			exp_node=poll(exp_queue);
			if(exp_node!=NULL){
				printf("polled %d\n",exp_node->val);
				free(exp_node);
			}
		}
		else if(strcmp(command,empty_queue_command)==0){
			empty_queue(exp_queue)==true?printf("true\n"):printf("false\n");
		}
		else if(strcmp(command,delete_command)==0){
			printf(">");
			scanf("%d",&delete_val);
			delete(delete_val,root);
		}
		else if(strcmp(command,pre_command)==0){
			//printf("in_count=%d pre_count=%d\n",in_count,pre_count);
			node* root_traversal=inorder_preorder(in_arr,pre_arr);
			breadth_first_check(root_traversal);
		}
	}
	return 0;
	
}