<commit_before>#include "bfs.h"

/* Function to initialise the attributes of each node */
void init_attributes(struct attributes *nodes, int n) {
	int i;
	for (i = 1; i <= n; i++) {
		nodes[i].parent = NIL;
		nodes[i].distance = INF;
		nodes[i].current_color = WHITE;
	}
}

/* Function to print the value of attributes */
void print_attributes(struct attributes *nodes, int n) {
	int i;
	printf("Node\tParent\tDistance\n");
	for (i = 1; i <= n; i++)
		printf("%4d : %6d\t%7d\n", i, nodes[i].parent, nodes[i].distance);
}

/* Function to implement BFS on a graph 
 * TODO: Replace `nodes` with a more appropriate name
 */
void bfs(struct Graph *graph, struct attributes *nodes, int source) {
	int i;
	struct Queue *Q;
	init_attributes(nodes, graph->V);
	to_list(graph);
	Q = init_queue(Q);
	
	nodes[source].current_color = GRAY;
	nodes[source].distance = 0;
	enqueue(Q, source);
	
	while (Q->first != NULL && Q->last != NULL) {	
		int current_node = dequeue(Q);
		struct node *iter = (graph->list[current_node]).head;
		while (iter != NULL) {
			if(nodes[iter->key].current_color == WHITE)
			{
				(nodes[iter->key]).current_color = GRAY;
				(nodes[iter->key]).distance = (nodes[current_node]).distance + 1;
				(nodes[iter->key]).parent = current_node;
				enqueue(Q, iter->key);
			}
			iter = iter->next;
		}
		nodes[current_node].current_color = BLACK;  	
	}
}<commit_msg>Remove init_attributes() function from BFS<commit_after>#include "bfs.h"

/* Function to print the value of attributes */
void print_attributes(struct attributes *nodes, int n) {
	int i;
	printf("Node\tParent\tDistance\n");
	for (i = 1; i <= n; i++)
		printf("%4d : %6d\t%7d\n", i, nodes[i].parent, nodes[i].distance);
}

/* Function to implement BFS on a graph
 * TODO: Replace `nodes` with a more appropriate name
 */
void bfs(struct Graph *graph, struct attributes *nodes, int source) {
	int i;
	struct Queue *Q;
	to_list(graph);
	Q = init_queue(Q);

	nodes[source].current_color = GRAY;
	nodes[source].distance = 0;
	enqueue(Q, source);

	while (Q->first != NULL && Q->last != NULL) {
		int current_node = dequeue(Q);
		struct node *iter = (graph->list[current_node]).head;
		while (iter != NULL) {
			if(nodes[iter->key].current_color == WHITE)
			{
				(nodes[iter->key]).current_color = GRAY;
				(nodes[iter->key]).distance = (nodes[current_node]).distance + 1;
				(nodes[iter->key]).parent = current_node;
				enqueue(Q, iter->key);
			}
			iter = iter->next;
		}
		nodes[current_node].current_color = BLACK;
	}
}
{'fraction_non_alphanumeric': 0.1684, 'fraction_numerical': 0.0052, 'mean_word_length': 3.9426877470355732, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '769810', 'n_tokens_mistral': 965, 'n_tokens_neox': 892, 'n_words': 228}