Ejemplo n.º 1
0
int main(){
	
	node_t* p;
    p = make_node(5);
    p = insert_val(6, p);
    p = insert_val(7, p);
	print_list(p);
	p = reverse_list(p);
	print_list(p);
	
}
Ejemplo n.º 2
0
int main()
	{
		inv_index<3,0> *index1;
		int att_values[3];
		int return_value;

		return_value = 0;
		index1 = new inv_index<3,0>;
		att_values[0] = 3;
		att_values[1] = 4;
		att_values[2] = 5;

		insert_val(att_values, index1);

		return_value = search_val(&(att_values[0]), index1);

		if (return_value == 1)
		{
			cout<<"values found"<<" "<<return_value<<endl;
		}
		else
		{
			cout<<"values not found"<<" "<<return_value<<endl;
		}

	}
Ejemplo n.º 3
0
static void *get_rssi_thread_routine(void *data) {
	struct routine_data_t *routine_data = (struct routine_data_t *)data;
	char *status = malloc(sizeof(char));
	memset(status, 0, sizeof(status));

	uint8_t i = routine_data->num_row;
	uint8_t j = routine_data->num_col;
	uint8_t num_captor = routine_data->num_captor;
	int16_t timeout = routine_data->timeout;
	hci_controller_t *hci_controller = routine_data->hci_controller; 
	bt_device_t sensor = routine_data->sensor;
	struct Matrix *matrice = routine_data->matrice;
	l2cap_client_t *client = routine_data->client;

	if (client) {
		if (!client->connected) {
			if (l2cap_client_connect(client) != 0) {	
				perror("client_connect : unable to connect client.");
				*status = 1;
				pthread_exit((void *)status);
			}
		}
		l2cap_client_send(client, 8000, CLIENT_GET_RSSI);
		if (client->buffer && (strcmp(client->buffer, "") != 0)) { 
			pthread_mutex_lock(&mutexMatrice);
			insert_val(matrice, i,j, num_captor, client->buffer);
			pthread_mutex_unlock(&mutexMatrice);
		} else {
			*status = 1;
		}
	} else {
		char * rssi_values;
		rssi_values = hci_LE_get_RSSI(NULL, hci_controller, NULL, NULL, NUM_MEASURES, 0x00, SCAN_INTERVAL, SCAN_WINDOW, 0x00, 0x01);
		fprintf(stderr, "%s\n", rssi_values);
		if (rssi_values && (strcmp(rssi_values, "") != 0)) {
			pthread_mutex_lock(&mutexMatrice);
			insert_val(matrice, i, j, NUM_CAPTORS-1, rssi_values);
			pthread_mutex_unlock(&mutexMatrice);
		} else {
			*status = 1;
		}
		free(rssi_values);

	}

	pthread_exit((void *)status);
}
Ejemplo n.º 4
0
	int main()
	{
		int att_array[3];
		int i = 0;
		TransactionManager transact_val1;
		dct_tree *tree_val = NULL;
		dct_tree *tree_val2 = NULL;
		dct_tree *tree_val3 = NULL;
		dct_node *temp = NULL;
		tree_val = build_dcttree(3);
		tree_val3 = build_dcttree(3);
		att_array[0] = 1;
		att_array[1] = 2;
		att_array[2] = 3;
		try
		{
			insert_val(att_array, tree_val, transact_val1);
			insert_val(att_array, tree_val3, transact_val1);
			//throw -1;
			transact_val1.commit_transaction();
			tree_val2 = copy_val((tree_val->getdummy()), (tree_val->getnumber_of_nodes()));
		}catch (int e)
		{
			cout<<"exception caught"<<" "<<e<<endl;
			return 1;
		}

		//att_array[2] = 3;
		if (search_val(att_array, tree_val))
		{
			cout<<"All values found"<<endl;
		}
		else
		{
			cout<<"All values not found"<<endl;
		}

		temp = search_val(att_array, tree_val2);
		if (temp != NULL)
		{
			cout<<" All values found copy tree"<<endl;
		}
		else
		{
			cout<<"All values not found copy tree"<<endl;
		}

		if (search_val(att_array, tree_val3))
		{
			cout<<"All values found3"<<endl;
		}
		else
		{
			cout<<"All values not found3"<<endl;
		}

		delete tree_val;
		delete tree_val2;
		delete tree_val3;
		delete temp;
	}
Ejemplo n.º 5
0
	void insert_skip(int a)
	{
		linked_list **traverse_skip = NULL;
		linked_list *traverse_list = NULL;
		linked_list *previous_pointer = NULL;
		linked_list *temp = NULL;
		int i = 0;
		int j = 0;
		int level = 0;
		int iteration_value = 0;

		level = level_generate();
		i = level - 1;

		if (level > max_level)
		{
			iteration_value = max_level;
		}
		else
		{
			iteration_value = level;
		}

		temp = (linked_list*)malloc(sizeof(linked_list));

		temp->setval(a);

		if (!list_array)
		{
			insert_val(a, 0, temp);
			return;
		}
		else
		{
			traverse_skip = (linked_list**)malloc(sizeof(linked_list*) * max_level);
		}

		traverse_list = list_array[level - 1];

		for (i = (level - 1);i >= 0;i--)
		{
			previous_pointer = NULL;

			if (j > 0)
			{
				while (j > 0)
				{
					traverse_list = traverse_list->getnext();
					--j;
				}
			}

			if (traverse_list == NULL)
			{
				cout<<"traverse_list is NULL"<<endl;
			}
			else
			{
				cout<<"traverse_list is not NULL"<<endl;
			}

			while (traverse_list != NULL && (traverse_list->getval()) < a)
			{
				cout<<"In loop 2"<<" "<<(traverse_list->getval())<<endl;
				++j;
				previous_pointer = traverse_list;
				traverse_list = traverse_list->getnext();
			}

			traverse_skip[i] = previous_pointer;

			traverse_list = list_array[i];
		}

		insert_val(0, j, temp);
		/*for (i = 1;i <= (level - 1);i++)
		{*/
			
	}
Ejemplo n.º 6
0
int main(int argc, char * argv[])
{
	const char * tree_str = 0;
	NODE * t = 0;
	int limit = -1;
	opterr = 0;
	______________________________  = print_nothing;
	______________________________I = print_nothing;
	______________________________D = print_nothing;

	while (1) {
		int c;
		static struct option long_options[] = {
			{"help",           no_argument,       0, 'h'},
			{"algorithm",      required_argument, 0, 'a'},
			{"debug-level",    required_argument, 0, 'd'},
			{"tree",           required_argument, 0, 't'},
			{"limit",          required_argument, 0, 'l'},
			{0, 0, 0, 0}
		};
		/* getopt_long stores the option index here. */
		int option_index = 0;
     
		c = getopt_long(argc, argv, "ha:t:d:l:",
				long_options, &option_index);
     
		/* Detect the end of the options. */
		if (c == -1)
			break;
     
		switch (c) {
		case 0:
			/* If this option set a flag, do nothing else now. */
			if(long_options[option_index].flag != 0)
				break;
			printf("option %s", long_options[option_index].name);
			if(optarg)
				printf(" with arg %s", optarg);
			printf("\n");
			break;

		case 'h':
			print_usage(argv[0]);
			break;
     
		case 'a':
			if (strcmp(optarg, "CLRS") == 0) {
				insert_val = insert_CLRS;
				delete_val = delete_CLRS;
			} else if (strcmp(optarg, "Sedgewick") == 0) {
				insert_val = insert_Sedgewick;
				delete_val = delete_Sedgewick;
			} else {
				abort();
			}
			break;
     
		case 'd':
			dbg_level = atoi_or_abort(optarg);
			if (dbg_level == 1) {
				______________________________  = print_rbtree;
			} else if (dbg_level == 2) {
				______________________________  = print_rbtree;
				______________________________I = print_rbtree;
			} else if (dbg_level == 3) {
				______________________________  = print_rbtree;
				______________________________D = print_rbtree;
			} else if (dbg_level == 4) {
				______________________________  = print_rbtree;
				______________________________I = print_rbtree;
				______________________________D = print_rbtree;
			} else {
				; /* use default */
			}
			break;
     
		case 't':
			tree_str = optarg;
			break;
          
		case 'l':
			limit = atoi_or_abort(optarg);
			break;
          
		case '?':
			/* getopt_long already printed an error message. */
			printf("%s%s%s\n", RED_B, argv[optind-1], NOCOLOR);
			break;
     
		default:
			abort();
		}
	}

	printf("%sDebug Level: %s%d%s\n", YELLOW, CYAN, dbg_level, NOCOLOR);

	static const char * default_tree[] = {/* p.275 */ "(26(17+(14(10+(7(3+)())(12))(16(15+)()))(21(19()(20+))(23)))(41(30+(28)(38(35+)(39+)))(47)))",
					      /* p.282 */ "(11(2+(1)(7(5+)(8+)))(14()(15+)))",
					      ""};
	if (!tree_str) {
		tree_str = default_tree[0];
		printf("%sUsing default tree: %s%s%s\n", YELLOW, CYAN, tree_str, NOCOLOR);
	}
	t = init_rbtree(tree_str);
	assert(t->L->P == nil);

        ______________________________("./fig/", t, t, "init");
	printf("Node count: %d\n", node_cnt);

	/* default algorithms */
	if (insert_val == 0)
		insert_val = insert_Sedgewick;
	if (delete_val == 0)
		delete_val = delete_Sedgewick;

	/* printf("optind: %d, argc: %d\n", optind, argc); */
	/* for (int j = 0; j < argc; j++) */
	/* 	printf("        %s\n", argv[j]); */
	if (optind < argc)
	{
		while (optind < argc) {
			char * a = argv[optind++];
			if (*a == '~')
				delete_val(t, atoi_or_abort(a+1));
			else
				insert_val(t, atoi_or_abort(a));
			verify_rbtree(t->L, 0);
		}
	} else {
		srand(time(NULL));
		if (limit == -1)
			limit = 100;
		printf("%sWill run %s%d%s tests.%s\n", YELLOW, CYAN, limit, YELLOW, NOCOLOR);
		while (t->L != nil && limit--) {
			int k = rand() % 50;
			int r = rand();
			if (dbg_level != 0)
				printf("random: %d\n", r);
			if (r % 2 != 0)
				insert_val(t, k);
			else
				if (rb_search(t, k) != 0)
					delete_val(t, k);
		}
		verify_rbtree(t->L, 0);
	}

	fprintf(stderr, "\n");
	print_rbtree("./fig/", t, t, "END");
	printf("Node count: %d\n", node_cnt);
	return 0;
}
void main()
{
	link_list mylist;

	init_list(&mylist);

	int select = 1;
	elem_type item;
	node *p = NULL;
	while(select)
	{
		printf("*************************************************\n");
		printf("*  [1] push_back	 [2] push_front 	*\n");
		printf("*  [3] show_list	 [4] pop_back    	*\n");
		printf("*  [5] pop_front	 [6] insert_val 	*\n");
		printf("*  [7] find 	 	 [8] get_length 	*\n");
		printf("*  [9] delete_val	 [10] sort   	 	*\n");
		printf("*  [11] resever		 [12] clear 	 	*\n");
		printf("*  [13*] destroy	 [0] quit_system 	*\n");
		printf("*  [14] prior_node 	 [15] next_node 	*\n");
		printf("*************************************************\n");

		printf("请选择操作选项:> ");
		scanf("%d", &select);

		if(select == 0)
			break;

		switch(select)
		{
			case 1:
				printf("请输入要插入的数据(-1结束):>");
				while(scanf("%d", &item), item != -1)
				{
					push_back(&mylist, item);
				}
				break;
			case 2:
				printf("请输入要插入的数据(头插法, -1结束);>");
				while(scanf("%d", &item), item != -1)
				{
					push_front(&mylist, item);
				}
				break;
			case 3:
				show_list(&mylist);
				break;
			case 4:
				pop_back(&mylist);
				break;
			case 5:
				pop_front(&mylist);
				break;
			case 6:
				printf("请输入要插入的数据:>");
				scanf("%d", &item);
				insert_val(&mylist, item);
				break;
			case 7:
				printf("请输入要查找的数据:>");
				scanf("%d", &item);
				p = find(&mylist, item);
				if (p == NULL)
				{
					printf("要查找的数据在单链表中不存在.");
				}
				else
				 	printf("在单链表查找到数据: %d\n", p->data);
				break;
			case 8:
				printf("单链表的长度为: %d\n", get_length(&mylist));
				break;
			case 9:
				printf("请输入要删除的值:> ");
				scanf("%d", &item);
				delete_val(&mylist, item);
				break;
			case 10:
				sort(&mylist);
				break;
			case 11:
				resver(&mylist);
				break;
			case 12:
				clear(&mylist);
				break;
			case 14:
				printf("请输入要查找的数据:>");
				scanf("%d", &item);
				p = prior_node(&mylist, item);
				if (p == NULL || p == (&mylist)->head)
				{
					printf("要查找的数据在单链表中不存在前驱.\n");
				}
				else
				{
			 	 	printf("要查找的数据在单链表中的前驱为:%d.\n", p->data);	
				}
				break;
 	 	 	case 15:
				printf("请输入要查找的数据:>");
				scanf("%d", &item);
				p = next_node(&mylist, item);
				if (p == NULL)
				{
					printf("要查找的数据在单链表中不存在后继.\n");
				}
				else
				{
			 	 	printf("要查找的数据在单链表中的后继为:%d.\n", p->data);	
				}
				break;

			default:
				printf("输入的选择有误,请重新输入.\n");
				break;
		}
	}
	destroy(&mylist);
}