Пример #1
0
Файл: sac.c Проект: iogf/sample
int main(void) {
	void * stack;
	double result;
	char type;
	char op;

	stack = initialize_stack(SIZE_INIT_STACK);

	/* check stack */

	do {
		prompt();

		type = gettype();

		if(type == UNKNOWN) {
			printf("Valid FUNCTIONS NUMBERS OR %s", FUNCTIONS);
			return 0;
		}

		if(type == EXIT)
			return 0;

		if(type == NUMBER) 
			push(atof(getop()));
		

		if(type == OPERAND) {

			if(!length_stack()) {
				printf("empty stack\n");
				continue;
			}
		
			result = calc();
			printf("\noutput%s%lf\n", PROMPT_SYMBOL, result);
			push(result);
		}
		

	} while(type != EXIT);

	return 0;
}
Пример #2
0
int main(int argc, char **argv)
{
	int l = 0, v = 0, a = 0;
	int j;
	for (j = 0; j < argc; j++)
	{
		if (strcmp(argv[j], "-l") == 0)
			l = 1;
		if (strcmp(argv[j], "-a") == 0)
			a = 1;
		if (strcmp(argv[j], "-v") == 0)
			v = 1;
	}
	
	int error_found = 0;
	
	initialize_la();
	
	error_found = program();
	if (error_found == 1)
	{
        int z = 0;
        for( z = 0; z < errorI ;z++){
             printf("%s", errorList[errors[errorI]]);
             }   
		return 0;
	}
	printf("No errors, program is syntactically correct\n\n");
	
	initialize_stack();
	
	if (l == 1)
		print_token_table();
	if (a == 1)
		print_list();
	if (v == 1)
		print_stack_list();
		
	print_token_table();
	print_list();
	print_stack_list();
	
	return 0;
}
Пример #3
0
void inorder_iterative(struct treenode *root) {
	struct stack S;
	initialize_stack(&S);

	while(true) {
		if(root) {
			push(&S, root);
			root = root->left;
		} else {
			if(!isEmpty(&S)) {
				root = pop(&S);
				printf("%d ", root->data);
				root = root->right;
			} else {
				break;
			}
		}
	}
}
Пример #4
0
list<SCC*> SCCSSEQ(AF gamma){
	stack<DFS_node*> G = initialize_stack(gamma);
	list<SCC*> list_SCC,dummy_list;
	// first call of DFS
	DFS(G,true,&dummy_list);

	// second call of DFS, considering edges in the opposite direction
	DFS(G,false,&list_SCC);

	list<SCC*>::iterator it;
	SCC* temp, temp2;

	for(it=list_SCC.begin();it!=list_SCC.end();it++){
		temp=*it;

		cout<<temp->set<<endl;
	}

	cout<<endl;

	return list_SCC;
}
Пример #5
0
int backtracking()
{
//Find the setof frames which minimizes the correlation as we done in ITG_3.2
//and also consider other metrics with meaningful weightage as follows
//	 metric			weightage	where(path traversal)
//(1)correlation	0.25		on fly
//(2)distance		0.25		on fly
//(3)brightness		0.125		|
//(4)blurriness		0.125		|________ create a matrix with weighted value
//(5)entropy		0.125		|			(of these 4 metrics)
//(6)face			0.125		|


	int i;
	int pos;
	int size = total_samples/n;
	abs_metrics = (float**)malloc(sizeof(float*)*n);
	for(i=0;i<n;i++) {
		abs_metrics[i]=(float*)malloc(sizeof(float)*size);
	}
	float best_metric;	
	cout<<"size:"<<size<<endl;
	flag = (int*) malloc(sizeof(int)*n);
	int* stack = (int*) malloc(sizeof(int)*n);
	index_samples =0;
//create a matrix with weighted value of all 4 metrics
// -brightness, -blurriness, -entropy, -face metric
	abs_metric_calc();
//show a 2D matrix
	show_matrix( abs_metrics,n,size);

	initialize_stack(stack );
#if TRACE_STEPS
	show_valid(stack);
#endif
	float present;
	i=0;
//	while(i<pow(size,n)) {
	while(stack_empty(stack)) {
#if TRACE_STEPS
		cout<<"i:"<<i<<endl;
		show_valid(stack);
#endif
		present = get_path_metrics(stack);
		if(i==0) {
			best_metric = present;
			copy(stack,flag,n);
#if PRINT_DEBUG
			cout<<"present:"<<present<<endl;
#endif
		}
		else if(present>best_metric) {
			best_metric = present;
			copy(stack,flag,n);
#if PRINT_DEBUG
			cout<<"present<best_corr:"<<best_metric<<endl;
			show_valid( flag);
#endif
		}
#if PRINT_DEBUG
		cout<<"correlation:"<<present<<"\t";
#endif
		stack_pop_push(stack);
		i++;
	}		
	return(0);
}
Пример #6
0
void initialize(void) {
    reset_stats();
    initialize_registers();
    initialize_stack();
    return;
}