Skip to content

feat: implement binary search tree for student records with insertion and display functions#1

Merged
ayoubkad merged 2 commits intomainfrom
modifi
Jan 23, 2026
Merged

feat: implement binary search tree for student records with insertion and display functions#1
ayoubkad merged 2 commits intomainfrom
modifi

Conversation

@ayoubkad
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings January 23, 2026 22:44
@ayoubkad ayoubkad merged commit 766a8a5 into main Jan 23, 2026
1 check passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a binary search tree (BST) structure for student records (sorted by moyenne) and integrates BST-based sorted display into the application and test suite.

Changes:

  • Added a new arbres_binaire module implementing BST node/root creation, insertion, and node cleanup.
  • Added BST-based sorted display (afficher_arbres_trie) and wired menu option #6 to build a temporary BST and print students in descending order.
  • Extended test_student.c with multiple BST-focused tests.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
arbres_binaire.h Declares BST node/root types and BST API for students.
arbres_binaire.c Implements BST node/root allocation, recursive insertion, and node freeing.
student.c Adds display_student() and implements sorted BST traversal/printing (afficher_arbres_trie).
student.h Exposes display_student() in the public header.
main.c Replaces list merge-sort call with temporary BST build + sorted display in menu option #6.
test_student.c Adds multiple BST unit/integration-style tests.
CMakeLists.txt Adds arbres_binaire.* to the main executable sources.
myApp Adds a compiled binary artifact to the repository.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +100 to +118
while (courent != NULL && strcmp(courent->CNE, cne) != 0) {
trouver = 1;
printf("\n");
printf("+--------------------------------------------+\n");
printf("| INFORMATION ETUDIANT |\n"); // J'ai ajouté %-2d pour l'alignement
printf("+--------------------------------------------+\n");
printf("| CNE : %-25.25s |\n", courent->CNE);
printf("| Nom : %-25.25s |\n", courent->nom);
printf("| Prenom : %-25.25s |\n", courent->prenom);
printf("| Date Naissance : %02d/%02d/%-19d |\n", courent->date_naissance.jour,
courent->date_naissance.mois, courent->date_naissance.annee);
printf("| Filiere : %-25.25s |\n", courent->filiere);
printf("| Moyenne : %-25.2f |\n", courent->moyenne);
printf("+--------------------------------------------+\n");
courent = courent->next;
}
if (trouver == 0) {
printf("etudiant n'est pas trouver!!!\n");
}
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

display_student(): the search loop is inverted—it's printing students while strcmp(...) != 0 and sets trouver=1 for non-matches, so it prints the wrong records and reports "not found" when the first element matches. Iterate through the list until a match is found; only print when strcmp(...)==0 and set trouver when a match is found (or break and handle "not found" after the loop).

Copilot uses AI. Check for mistakes.
Comment on lines +96 to 108
ab_racine_student *temp_tree = create_ab_racine();
// temp_tree->racine = NULL;

student *current_s = my_db->tete;
while (current_s != NULL) {
ab_node_student *new_node = create_ab_node(current_s);
insert_bst(temp_tree, new_node);
current_s = current_s->next;
}

afficher_arbres_trie(temp_tree);
free_bst_nodes(temp_tree->racine);
break;
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case 6: temp_tree is never freed, so each sort operation leaks memory. Also create_ab_racine() can return NULL; in that case free_bst_nodes(temp_tree->racine) will dereference NULL. Check temp_tree != NULL before use, and free(temp_tree) after freeing its nodes (or add a helper that frees both root and wrapper).

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,25 @@
#ifndef MINI_DATABASE_ARBRES_BINAIRE_H
#define MINI_DATABASE_ARBRES_BINAIRE_H
#include "undo_stack.h"
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arbres_binaire.h includes undo_stack.h, but the tree API only needs the student type. Including undo_stack.h creates unnecessary coupling and can introduce circular dependencies; include student.h (or forward-declare struct student) instead and keep undo stack concerns separate.

Suggested change
#include "undo_stack.h"
#include "student.h"

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,57 @@
#include <stdlib.h>
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arbres_binaire.c starts with a UTF-8 BOM before the #include ("#include..."). This can break compilation on some toolchains; remove the BOM so the file begins directly with #include.

Suggested change
#include <stdlib.h>
#include <stdlib.h>

Copilot uses AI. Check for mistakes.
Comment on lines +33 to +42
ab_node_student *insert_recursive_worker(ab_node_student *currant, ab_node_student *new_node) {
if (currant == NULL) return new_node;

if (new_node->std->moyenne < currant->std->moyenne) {
currant->filsg = insert_recursive_worker(currant->filsg, new_node);
} else {
currant->filsd = insert_recursive_worker(currant->filsd, new_node);
}
return currant;
}
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insert_recursive_worker() is not declared in the header but is currently a global symbol. Since it is only used inside arbres_binaire.c, mark it static to avoid exporting an unintended API surface and reduce the risk of symbol collisions.

Copilot uses AI. Check for mistakes.
Comment on lines +94 to +99
void display_student(list_student *list_student, char *cne) {
if (list_student == NULL || list_student->tete == NULL) {
printf("la Base de donnee et vide!!!\n");
}
int trouver = 0;
student *courent = list_student->tete;
Copy link

Copilot AI Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

display_student(): after printing that the database is empty, the function continues and dereferences list_student->tete, which will crash when list_student==NULL. Add an early return when list_student==NULL or list_student->tete==NULL (and consider validating cne as well).

Copilot uses AI. Check for mistakes.
@ayoubkad ayoubkad deleted the modifi branch January 23, 2026 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants