Skip to content

Commit e76e4f9

Browse files
committed
Adding comments
1 parent c4f0653 commit e76e4f9

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

chapters/fundamental_algorithms/tree_traversal.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ typedef struct node_points{
352352
} node_points;
353353

354354
void push(node_points *np, node *n){
355+
// Adding node into a queue or a stack
355356
node_list *temp = (node_list*)malloc(sizeof(node_list));
356357
temp->n = *n;
357358
temp->last_list = temp->next_list = NULL;
@@ -366,6 +367,7 @@ void push(node_points *np, node *n){
366367
}
367368

368369
void stack_pop(node_points *np){
370+
// Removing the last node_list of the stack
369371
node_list *temp;
370372
temp = np->end_point;
371373
if(temp){
@@ -378,6 +380,7 @@ void stack_pop(node_points *np){
378380
}
379381

380382
void queue_pop(node_points *np){
383+
// Removing the first node_list of the queue
381384
node_list *temp;
382385
temp = np->start_point;
383386
if(temp){
@@ -421,6 +424,7 @@ void DFS_recursive(node *n){
421424
}
422425

423426
void DFS_stack(node *n){
427+
// Creating a stack and then setting its value to 0
424428
node_points stack;
425429
memset(&stack, 0, sizeof(node_points));
426430
push(&stack, n);
@@ -431,6 +435,7 @@ void DFS_stack(node *n){
431435
printf("%d\n", temp.ID);
432436
stack_pop(&stack);
433437
for(int i=0; i < temp.children_num; ++i){
438+
// Checking if the node has any children
434439
if(!temp.children){
435440
break;
436441
}
@@ -440,6 +445,7 @@ void DFS_stack(node *n){
440445
}
441446

442447
void BFS_queue(node *n){
448+
// Creating a queue and then setting its value to 0
443449
node_points queue;
444450
memset(&queue, 0, sizeof(node_points));
445451
push(&queue, n);
@@ -450,6 +456,7 @@ void BFS_queue(node *n){
450456
printf("%d\n", temp.ID);
451457
queue_pop(&queue);
452458
for(int i = 0; i < temp.children_num; ++i){
459+
// Checking if the node has any children
453460
if(!temp.children){
454461
break;
455462
}
@@ -459,6 +466,7 @@ void BFS_queue(node *n){
459466
}
460467

461468
void destroy_tree(node *n){
469+
// This function is for cleaning up all the nodes
462470
if(n->ID == 0){
463471
return;
464472
}

0 commit comments

Comments
 (0)