Example #1
0
void benchmark(Graf& cos, int poczatek, int koniec, std::ostream& out) {

	std::chrono::time_point<std::chrono::system_clock> start, end;
	std::chrono::duration<double> elapsed_time(0);

	start = std::chrono::system_clock::now();
	auto list = depth_first(cos, poczatek, koniec);
	end = std::chrono::system_clock::now();
	elapsed_time = end-start;
	out << "DEPTH-FIRST time: " << elapsed_time.count()  << "s. ";
	for( auto t : list ) std::cerr << t << " -> "; std::cerr << "\n";


	start = std::chrono::system_clock::now();
	list = breadth_first(cos, poczatek, koniec);
	end = std::chrono::system_clock::now();
	elapsed_time = end-start;
	out << "BREADTH-FIRST time: " << elapsed_time.count()  << "s. ";
	for( auto t : list ) std::cerr << t << " -> "; std::cerr << "\n";

	start = std::chrono::system_clock::now();
	list = a_star(cos, poczatek, koniec );
	end = std::chrono::system_clock::now();
	elapsed_time = end-start;
	out << "A* time: " << elapsed_time.count()  << "s. ";
	for( auto t : list ) std::cerr << t << " -> "; std::cerr << "\n";

}
Example #2
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;
	
}