Пример #1
0
// [Q3 - 10pts] Implement the insert function.   The function should check 
// if existing order has been made (using the order id).   If an order 
// exist, update the record. Otherwise, insert a new order into the queue 
// – follow FIFO.      
int insert_order(struct Order* item) {

	/* -- START CODING HERE -- */
	struct Order *ptr = Queue;
	int indicator = update_order(item);

	if (indicator == -1) {
		if (!ptr) {
			item->next = NULL;
			Queue = item;

			return 0;
		}
		else {
			while (ptr->next != NULL) {
				ptr = ptr->next;
			}

			item->next = NULL;
			ptr->next = item;
		}
	}
	/* -- END CODING HERE -- */

	return 0;
}
Пример #2
0
bool __connman_connection_update_gateway(void)
{
	struct gateway_data *default_gateway;
	bool updated = false;
	GHashTableIter iter;
	gpointer value, key;

	if (!gateway_hash)
		return updated;

	update_order();

	default_gateway = find_default_gateway();

	__connman_service_update_ordering();

	DBG("default %p", default_gateway);

	/*
	 * There can be multiple active gateways so we need to
	 * check them all.
	 */
	g_hash_table_iter_init(&iter, gateway_hash);

	while (g_hash_table_iter_next(&iter, &key, &value)) {
		struct gateway_data *active_gateway = value;

		if (active_gateway == default_gateway)
			continue;

		if (active_gateway->ipv4_gateway &&
				active_gateway->ipv4_gateway->active) {

			unset_default_gateway(active_gateway,
						CONNMAN_IPCONFIG_TYPE_IPV4);
			updated = true;
		}

		if (active_gateway->ipv6_gateway &&
				active_gateway->ipv6_gateway->active) {

			unset_default_gateway(active_gateway,
						CONNMAN_IPCONFIG_TYPE_IPV6);
			updated = true;
		}
	}

	if (updated && default_gateway) {
		if (default_gateway->ipv4_gateway)
			set_default_gateway(default_gateway,
					CONNMAN_IPCONFIG_TYPE_IPV4);

		if (default_gateway->ipv6_gateway)
			set_default_gateway(default_gateway,
					CONNMAN_IPCONFIG_TYPE_IPV6);
	}

	return updated;
}
Пример #3
0
// [Q2 - 5pts]	Write code to capture customerNo, cost, name, address, and item
// into the new created struct Order pointed by ptr.  Assume name, address, and item
// cannot accept any spaces or return characters.  
int insert_update_order_helper(char c) {

	struct Order *ptr = (struct Order *)malloc(sizeof(struct Order));

	/* -- START CODING HERE -- */
	printf("What is the order id? ");
	scanf("%d", &ptr->orderid);

	printf("What is your customer id? ");
	scanf("%d", &ptr->customerNo);

	printf("What is your name? ");
	scanf("%s", ptr->name);

	printf("What is your address? (No spaces) ");
	scanf("%s", ptr->address);

	printf("What is the item? ");
	scanf("%s", ptr->item);

	printf("What is the cost? ");
	scanf("%f", &ptr->cost);

	ptr->next = NULL;
	/* -- END CODING HERE -- */

	if (c == 'i') {
		return insert_order(ptr);
	}
	else {
		int value = update_order(ptr);

		if (value == -1) { printf("No Record Found."); }

		return update_order(ptr);
	}
}
Пример #4
0
void grobner::update_order(equation_set & s, bool processed) {
    ptr_buffer<equation> to_remove;
    equation_set::iterator it  = s.begin();
    equation_set::iterator end = s.end();
    for (;it != end; ++it) {
        equation * eq = *it;
        if (update_order(eq)) {
            if (processed) {
                to_remove.push_back(eq);
                m_to_process.insert(eq);
            }
        }
    }
    ptr_buffer<equation>::iterator it2  = to_remove.begin();
    ptr_buffer<equation>::iterator end2 = to_remove.end();
    for (; it2 != end2; ++it2)
        s.erase(*it2);
}
Пример #5
0
void grobner::update_order() {
    update_order(m_to_process, false);
    update_order(m_processed, true);
}