Le tri sur les listes chaînées

Fermé
Nemad - 4 juil. 2020 à 12:14
yg_be Messages postés 22724 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 25 avril 2024 - 4 juil. 2020 à 12:23
bonjour j'aimerais que l'on m'aide à faire le tri de mon projet en c.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct etudiant
{ char nom[30];
char prenom[30];
char matricule[10];
struct etudiant *suivetu;
}etudiant;

etudiant *tete,*ptete,*queue;

int choix,i,choix1;
char mon_choix[3];
void saisir();
void afficher();
void supprimer();
void quitter();
void rechercher();
void ajouter();
void menu();

char eurreur( char *t){
int i,euror=0;
etudiant *temp;
temp=tete;
if(temp!=NULL){
while(temp!=NULL){
if(stricmp(temp->matricule,t)==0){
euror=1;

}
temp=temp->suivetu;
}

}
return euror;
}

main(){
tete=NULL;
queue=NULL;
menu();
}
void menu(){
char choix[10];int MENU;
while(choix[0]!='6'){
printf("==========================================\n");
printf("| MENU |\n");
printf("| 1 ajouter |\n");
printf("| 2 afficher |\n");
printf("| 3 rechercher |\n");
printf("| 4 supprimer |\n");
printf("| 5 trier |\n");
printf("| 6 quitter |\n");
printf("| |\n");
printf(" ========================================");


printf("\n");
printf("\t Votre choix: ");
scanf("%s",choix);
MENU=strlen(choix);
if(MENU==1){
switch(choix[0]){
case '1' :ajouter() ;break;
case '2' :afficher() ;break;
case '3' :rechercher() ;break;
case '4' :supprimer() ;break;
// case '5' :Trier() ;break;
case '6' :quitter() ;break;


default:printf("\n Erreur choix invalide ");system("pause");
}
}
}
}
void quitter(){
printf("\t\tCode par Nabaloum Irenee & Zongo Aime !!!!! \t\t\n");
printf("\t\tMerci Dr OUATTARA !!!!!!\t\t\n");
system("pause>null");
}
void ajouter(){
int choix;
int KAG,i=1;
do{
ptete = (etudiant*)malloc(sizeof(struct etudiant));
printf("\n Entrer les informations de l'etudiant %d \n\n",i);
printf("Entrer le nom: ");
scanf("%s",ptete->nom);
printf("\n");
printf("Entrer le prenom de %s : ",ptete->nom);
scanf("%s",ptete->prenom);
printf("\n");
printf("Entrer la matricule de %s %s : ",ptete->nom,ptete->prenom);
scanf("%s",ptete->matricule);
while(eurreur(ptete->matricule)){
printf("Cette matricule existe deja !!!!!!!\n\n");
printf("Entrer la matricule %s %s : ",ptete->nom,ptete->prenom);
scanf("%s",ptete->matricule);
}
ptete->suivetu=tete;
tete=ptete;
i++;
printf("\n\n\t\tEntrer 1 pour continuer ou 0 pour arreter: ");
scanf("%d",&choix);
}while(choix!=0);
printf("\n\n\t\tSaisie effectuee avec succes \n\n");
system("pause");
}
void afficher()
{
queue=tete;
int i=1;
if(queue==NULL)
{
printf("Liste vide!!!\n");
}
else{
printf("\n affichage \n\n");
while(queue!=NULL){
printf("Etudiant %d: \n",i);
printf("Nom: %s\n",queue->nom);
printf("prenom: %s\n",queue->prenom);
printf("Matricule: %s\n\n",queue->matricule);
queue=queue->suivetu;
i++;
}
}
system("pause");
}

void supprimer(){
if(tete==NULL){
printf("Liste vide!!!!!!!\n");
system("pause");
}
if(tete!=NULL){
char mat[30];etudiant *prec;etudiant *soudeur;
printf("Entrer la matricule de l'etudiant a supprimer: \n");
scanf("%s",mat);
prec=(etudiant*)malloc(sizeof(etudiant));
soudeur=(etudiant*)malloc(sizeof(etudiant));
prec=tete;
if(stricmp(prec->matricule,mat) == 0){
tete=prec->suivetu;
free(prec);
printf("\n\n\t\tSuppression reussie...........\n\n\n");
}
else{

soudeur=prec->suivetu;
while(soudeur!=NULL){
if(stricmp(soudeur->nom,mat) == 0){
prec->suivetu=soudeur->suivetu;
free(soudeur);
}
prec=soudeur;
soudeur=soudeur->suivetu;
printf("Cet etudiant n'est pas le premier element de la liste\n\n");
}
system("pause");
}
}
}
void rechercher(){
if(tete==NULL){
printf("Liste vide!!!!!!!\n");
system("pause");
}
if(tete!=NULL){
int i=1;
char name[30];etudiant *prec;
char prenom[30];
printf("Entrer le nom de l'etudiant a rechercher\n");
scanf("%s",&name);
prec=(etudiant*)malloc(sizeof(etudiant));
prec=tete;
while(prec!=NULL){

if(stricmp(prec->nom,name) == 0)
{
printf("\n affichage \n\n");
printf("Etudiant %d : \n",i);
printf("Nom: %s\n",prec->nom);
printf("Prenom: %s\n",prec->prenom);
printf("Matricule: %s\n",prec->matricule);
prec=prec->suivetu;
i++;
}
else{
printf("Cet etudiant n'est pas le premier element de la liste\n\n");
system("pause");
menu();
}
}
system("pause");
}
}
void saisir(){
int choix;
do{
ptete = (etudiant*)malloc(sizeof(struct etudiant));
printf("\n-Entrer les informations de l'etudiant a ajouter: \n\n");
printf("\n-Entrer le nom :\t ");
scanf("%s",ptete->nom);
printf("\n");
printf("Entrer le prenom de :\t ");
scanf("%s",ptete->prenom);
printf("\n");
printf("Entrer la matricule de :\t ");
scanf("%s",ptete->matricule);
while(eurreur(ptete->matricule))
{
printf("Cette matricule existe deja!!!!!!!\n\n");
printf("Entrer la matricule de %s %s a ajouter: ",ptete->nom,ptete->prenom);
scanf("%s",ptete->matricule);
}
ptete->suivetu=tete;
tete=ptete;
i++;
printf("\n\n\t\tEntrer 1 pour continuer ou 0 pour arreter: ");
scanf("%d",&choix);
}while(choix!=0);
printf("\n\n\t\tAjout effectue avec succes \n\n");
system("pause");
}

1 réponse

yg_be Messages postés 22724 Date d'inscription lundi 9 juin 2008 Statut Contributeur Dernière intervention 25 avril 2024 1 476
4 juil. 2020 à 12:23
bonjour, avant tout, merci d'utiliser les balises de code quand tu publies du code: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
ensuite, précise quelle aide tu demandes.
0