[[Template core/front/global/updateWarning is throwing an error. This theme may be out of date. Run the support tool in the AdminCP to restore the default theme.]]
كيف نقوم بترتيب بيانات مدخلة في قائمة عادية ؟ البرنامج التالي يقوم بقراءة بيانات طلبة في قائمة عادية ثم اخراجها على الشاشه ثم ترتيبها حسب معدلات الطلبة لكن عندي مشكلة في دالة الترتيب ، ارجو المساعدة بارك الله فيكم
#include<stdlib.h>#include<stdio.h>typedef struct student{ int nbr; char fname[10]; char lname[10]; float mark; int class; struct student*suivant;}BAC;typedef BAC*liste;//Fonction Insertliste Insert(liste p){ liste new=(liste)malloc(sizeof(BAC)); do { printf("enter the mark\t"); scanf("%f",&new->mark); }while(new->mark < 12); printf("enter the number\t"); scanf("%d",&new->nbr); printf("enter the first name\t"); scanf("%s",new->fname); printf("enter the last name\t"); scanf("%s",new->lname); if(new->mark < 13) new->class=3; else if(new->mark < 15) new->class=2; else new->class=1; new->suivant=p; p=new; return p;}//Function Displayvoid Display(liste p){ liste temp=p; if(temp != NULL) { printf("\n number:%d",temp->nbr); printf("\n first & last name:%s %s",temp->fname,temp->lname); printf("\n the mark:%f",temp->mark); switch (temp->class) { case 3: printf("\n class:C");break; case 2: printf("\n class:B");break; case 1: printf("\n class:A");break; } printf("\n-------------------------\n"); Display(temp->suivant); }}//Function Sortvoid Sort(list p){ list cour,av_cour=p; for (av_cour=p ; av_cour->suivant!= NULL ; av_cour=av_cour->suivant) { for (cour=p->suivant ; cour->suivant!= NULL ; cour=cour->suivant) { if(cour->mark < av_cour->mark) { list temp=(list)malloc(sizeof(BAC)); temp=cour; temp->suivant=av_cour; av_cour->suivant=cour->suivant; cour=temp; free(temp); } } } Display(p);}main(){ list p=NULL; int i,n; printf("enter the number of students:\t"); scanf("%d",&n); printf("\n<===============ENTER LIST DATA================>\n"); for(i = 1 ; i <= n ; i++) { p=Insert(p); } printf("\n<==============DISPLAY LIST DATA===============>\n"); Display(p); printf("\n<==================SORT DATA===================>\n"); Sort(p); return 0;system("pause") ;}
تم النشر منذ
السلام عليكم و رحمة الله و بركاته
كيف نقوم بترتيب بيانات مدخلة في قائمة عادية ؟ البرنامج التالي يقوم بقراءة بيانات طلبة في قائمة عادية ثم اخراجها على الشاشه ثم ترتيبها حسب معدلات الطلبة لكن عندي مشكلة في دالة الترتيب ، ارجو المساعدة بارك الله فيكم
شارك هذا الرد
رابط المشاركة
شارك الرد من خلال المواقع ادناه