#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct module {
char name[10];
int note;
struct module * next;
};
typedef struct module module;
struct student {
char name[10];
char adress[20];
struct student * next;
module * head;
} ;
typedef struct student student;
student *etudiant=NULL;
module* add_module(char name[],int note){
module *p=(module*)malloc(sizeof(module));
p->note=note;
p->next=NULL;
strcpy(p->name,name);
return p;
}
void add_student(char name[], char adress[])
{
student *p=(student*)malloc(sizeof(student));
strcpy(p->name,name);
strcpy(p->adress,adress);
p->head= add_module("algo",15);
p->next=NULL;
if (etudiant==NULL){
etudiant=p;
}
else{
student *q = etudiant;
while(q->next!=NULL){
q=q->next;
}
q->next=p;
}
}
void print_module(module *m){
if (m==NULL)
{
printf("NULL");
}
else
{
while(m->next!=NULL){
printf("%s ",m->name);
printf("%d\n",m->note);
m=m->next;
}
}
}
void print(){
student *p;
module *m;
p = etudiant;
if (etudiant==NULL){
printf("NULL");
}
else
{
while (p->next!=NULL);
{
printf("%s ",etudiant->name);
printf("%s ",etudiant->adress);
m = p->head;
while(m != NULL){
printf("%s ",m->name);
printf("%d ",m->note);
m= m->next;
}
p = p->next;
}
}
}
int main() {
add_student("jack","nowhere");
print();
return 0;
}
Was will ich eine Liste in einer Liste exemple erstellenverknüpfte Liste in einer verknüpften Liste (verschachtelte verknüpfte Liste)
Student list :
Student || subject || ==> student 2 || subject
| |
maths POO
| |
physiques English
, die eine ungefähre paiting meiner Struktur ist, ich kam ein Thema hinzufügen zu einem Studenten, aber ich weiß nicht, wie man mehr hinzufügt. danke im voraus.
I definiert die Schüler Liste als global, da ich nur eine Liste aller Studenten
Was Ihre Frage ist? –
Ich habe meine Frage bearbeitet –
Was ist Modul? ist es innerhalb von Studenten? – Sean83