@@ -352,6 +352,7 @@ typedef struct node_points{
352
352
} node_points;
353
353
354
354
void push (node_points * np, node * n){
355
+ // Adding node into a queue or a stack
355
356
node_list * temp = (node_list* )malloc(sizeof(node_list));
356
357
temp->n = * n;
357
358
temp->last_list = temp->next_list = NULL;
@@ -366,6 +367,7 @@ void push(node_points *np, node *n){
366
367
}
367
368
368
369
void stack_pop(node_points * np){
370
+ // Removing the last node_list of the stack
369
371
node_list * temp;
370
372
temp = np->end_point;
371
373
if(temp){
@@ -378,6 +380,7 @@ void stack_pop(node_points *np){
378
380
}
379
381
380
382
void queue_pop(node_points * np){
383
+ // Removing the first node_list of the queue
381
384
node_list * temp;
382
385
temp = np->start_point;
383
386
if(temp){
@@ -421,6 +424,7 @@ void DFS_recursive(node *n){
421
424
}
422
425
423
426
void DFS_stack(node * n){
427
+ // Creating a stack and then setting its value to 0
424
428
node_points stack;
425
429
memset(&stack, 0, sizeof(node_points));
426
430
push(&stack, n);
@@ -431,6 +435,7 @@ void DFS_stack(node *n){
431
435
printf("%d\n", temp.ID);
432
436
stack_pop(&stack);
433
437
for(int i=0; i < temp.children_num; ++i){
438
+ // Checking if the node has any children
434
439
if(!temp.children){
435
440
break;
436
441
}
@@ -440,6 +445,7 @@ void DFS_stack(node *n){
440
445
}
441
446
442
447
void BFS_queue(node * n){
448
+ // Creating a queue and then setting its value to 0
443
449
node_points queue;
444
450
memset(&queue, 0, sizeof(node_points));
445
451
push(&queue, n);
@@ -450,6 +456,7 @@ void BFS_queue(node *n){
450
456
printf("%d\n", temp.ID);
451
457
queue_pop(&queue);
452
458
for(int i = 0; i < temp.children_num; ++i){
459
+ // Checking if the node has any children
453
460
if(!temp.children){
454
461
break;
455
462
}
@@ -459,6 +466,7 @@ void BFS_queue(node *n){
459
466
}
460
467
461
468
void destroy_tree(node * n){
469
+ // This function is for cleaning up all the nodes
462
470
if(n->ID == 0){
463
471
return;
464
472
}
0 commit comments