Example #1
0
int main() {
	int i, j, s, sum=0;
	UNDIRECTED first=NULL, min;
	printf("Enter number of vertices\n");
	scanf("%d", &n);
	for(i=0;i<n;i++) {
		for(j=0;j<n;j++) {
			scanf("%d", &input[i][j]);
		}
	}
	printf("Enter source\n");
	scanf("%d", &s);
	reset_all();
	remove_element_array(vertex, &vindex, s);
	push_array(finished, &findex, s);
	while(findex<n-1) {
		for(i=0;i<=findex;i++) {
			for(j=0;j<=vindex;j++) {
				first=insert_ll(first, new_connection(finished[i], vertex[j]));
			
			}
		}
		min=find_minimum(first);
		push_array(finished, &findex, min->d);
		remove_element_array(vertex, &vindex, min->d);
		first=destroy_ll(first);
		sum+=distance(min->s, min->d);
		printf("%d->%d = %d\n", min->s, min->d, distance(min->s, min->d));
	}
	printf("Total distance = %d\n", sum);
	return 0;
}
Example #2
0
void insert(struct Hashtable *h, char *str)
{
    int index = hash(str, h->length);

    if(h->table[index].string == NULL){         //if there is no string alrady stored in the array store the string there
        h->table[index].string = str;
    }else{                                  //conflicting indexes so create a new Node to branch off and store the string 
        insert_ll(&(h->table[index]), str);
    }
}
Example #3
0
void read_ast_rules(){
	asr = (ast_rules) malloc(NUM_RULES*sizeof(ast_rule));
	int i;
	FILE *fp = fopen("astrules.txt","r");
	char s[300];
	for(i=0;i<num_rules;i++){
		fgets(s,300,fp);
		asr[i].rhs = new_LL();
		int bs=0,b,num;
		while(sscanf(s+bs,"%d%n",&num,&b)>0){
			asr[i].rhs = insert_ll(asr[i].rhs,num);
			bs += b;
		}
		Node *it = asr[i].rhs.head;
	}
	strcpy(symbols[200],"Mat_Elem");
}