Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion arbres_binaire.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "student.h"
#include "arbres_binaire.h"

ab_node_student *create_ab_node(student *student) {
Expand Down
3 changes: 2 additions & 1 deletion arbres_binaire.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef MINI_DATABASE_ARBRES_BINAIRE_H
#define MINI_DATABASE_ARBRES_BINAIRE_H
#include "undo_stack.h"

typedef struct student student;

// structure de node d'arbre
typedef struct ab_node_student {
Expand Down
7 changes: 3 additions & 4 deletions hash_table.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "student.h"
#include "hash_table.h"

unsigned int hash(const char *key) {
Expand All @@ -23,7 +24,7 @@ hash_table *createTable() {
void insert_hash(hash_table *ht, student *s) {
if (ht == NULL || s == NULL) return;

unsigned int index = hash(s->CNE);
const unsigned int index = hash(s->CNE);
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

The const qualifier is added to the index variable, but index is assigned once and never modified, so this is a good practice. However, since this variable is local and immediately used, the const keyword provides minimal benefit. This is acceptable but not critical.

Copilot uses AI. Check for mistakes.

node_hash *new_node = (node_hash *) malloc(sizeof(node_hash));
if (new_node == NULL) {
Expand All @@ -42,7 +43,7 @@ void insert_hash(hash_table *ht, student *s) {
ht->table[index] = new_node;
}

student *search(hash_table *ht, const char *key) {
student *search_hash(hash_table *ht, const char *key) {
if (ht == NULL || key == NULL) {
return NULL;
}
Expand All @@ -55,8 +56,6 @@ student *search(hash_table *ht, const char *key) {
}
temp = temp->next;
}

printf("L'étudiant de CNE %s n'existe pas!!!\n", key);
return NULL;
}

Expand Down
6 changes: 3 additions & 3 deletions hash_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#define MINI_DATABASE_HASH_TABLE_H

#define TABLE_SIZE 131
#include "student.h"

typedef struct node_hash {;
typedef struct student student;
typedef struct node_hash {
char *key;
student *value;
struct node_hash *next;
Expand All @@ -20,7 +20,7 @@ hash_table *createTable();

void insert_hash(hash_table *ht, student *s);

student *search(hash_table *ht, const char *key);
student *search_hash(hash_table *ht, const char *key);

void delete_student_hash(hash_table *ht, const char *key);

Expand Down
22 changes: 16 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "student.h"
#include "hash_table.h"
#include "arbres_binaire.h"
#include "undo_stack.h"
// #include <windows.h> // pour les Accents
Expand All @@ -16,8 +18,16 @@ int main() {
// SetConsoleOutputCP(65001); // pour les Accents
list_student *my_db = creat_list_student();
UndoStack *my_stack = create_undo_stack();
hash_table *table_hachage = createTable();

load_database(my_db, "my_data.db");

// Peupler la table de hachage avec les données chargées
populate_hash_table(table_hachage, my_db);

int choice = 0;
int sub_choice = 0;

char cne_buffer[15];

do {
Expand Down Expand Up @@ -61,7 +71,7 @@ int main() {
scanf("%f", &s->moyenne);
while (getchar() != '\n');
}
add_student(my_db, s, my_stack);
add_student(table_hachage, my_db, s, my_stack);
break;
}
case 2:
Expand All @@ -71,7 +81,7 @@ int main() {
printf("\nEntrez le CNE de l'etudiant a supprimer : ");
fgets(cne_buffer, 15, stdin);
cne_buffer[strcspn(cne_buffer, "\n")] = 0;
delete_student(my_db, cne_buffer, my_stack);
delete_student(table_hachage,my_db, cne_buffer, my_stack);
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

Missing space after the comma in the function call. Should be "delete_student(table_hachage, my_db, cne_buffer, my_stack);" for consistency with formatting conventions.

Suggested change
delete_student(table_hachage,my_db, cne_buffer, my_stack);
delete_student(table_hachage, my_db, cne_buffer, my_stack);

Copilot uses AI. Check for mistakes.
break;
case 4:
printf("\nEntrez le CNE de l'etudiant a modifier : ");
Expand All @@ -84,7 +94,7 @@ int main() {
printf("\nEntrez le CNE de l'etudiant a rechercher : ");
fgets(cne_buffer, 15, stdin);
cne_buffer[strcspn(cne_buffer, "\n")] = 0;
search_student_by_cne(my_db, cne_buffer);
search_student_by_cne(table_hachage, cne_buffer);
break;
case 6:
// sort_students_by_grade(my_db);
Expand Down Expand Up @@ -114,13 +124,12 @@ int main() {
scanf("%d", &confirm);
while (getchar() != '\n');
if (confirm == 1) {
delete_all_students(my_db);
delete_all_students(table_hachage, my_db);
} else {
printf("Operation annulee.\n");
}
break;
case 8:
int sub_choice = 0;
printf("\n--- MENU HISTORIQUE ---\n");
printf("1. Afficher la liste des actions (Voir l'historique)\n");
printf("2. Annuler la derniere action (Undo)\n");
Expand All @@ -133,7 +142,7 @@ int main() {
if (sub_choice == 1) {
display_undo_history(my_stack);
} else if (sub_choice == 2) {
execute_undo(my_db, my_stack);
execute_undo(table_hachage, my_db, my_stack);
} else if (sub_choice == 0) {
printf("Retour au menu principal...\n");
} else {
Expand All @@ -142,6 +151,7 @@ int main() {
break;
case 9:
save_database(my_db, "my_data.db");
free_table(table_hachage);
free_undo_stack(my_stack);
printf("Donnees sauvegardees. Au revoir!\n");
break;
Expand Down
Binary file renamed myApp → mini_db
Binary file not shown.
Binary file modified my_data.db
Binary file not shown.
Loading