56 lines
896 B
C
56 lines
896 B
C
|
#include<stdio.h>
|
||
|
#include<stdlib.h>
|
||
|
#include<time.h>
|
||
|
|
||
|
struct maillon_s {
|
||
|
unsigned short valeur;
|
||
|
struct maillon_s* suivant;
|
||
|
};
|
||
|
|
||
|
typedef struct maillon_s maillon;
|
||
|
typedef maillon* liste;
|
||
|
|
||
|
void list(liste l) {
|
||
|
maillon* m = l;
|
||
|
while (m != NULL) {
|
||
|
printf("%3hu ", m->valeur);
|
||
|
m = m->suivant;
|
||
|
}
|
||
|
puts("");
|
||
|
}
|
||
|
|
||
|
unsigned short max(liste l) {
|
||
|
maillon* m = l;
|
||
|
unsigned short max = 0;
|
||
|
|
||
|
while (m != NULL) {
|
||
|
if (m->valeur > max) max = m->valeur;
|
||
|
m = m->suivant;
|
||
|
}
|
||
|
|
||
|
return max;
|
||
|
}
|
||
|
|
||
|
int main(int argc, char * argv[]) {
|
||
|
liste l;
|
||
|
maillon* last_m = NULL;
|
||
|
|
||
|
srand(time(NULL));
|
||
|
for (int i = 0; i < 10; i++) {
|
||
|
srand(rand());
|
||
|
unsigned short random = rand() % (999-111) + 111;
|
||
|
maillon* new_m = malloc(sizeof(maillon));
|
||
|
new_m->valeur = random;
|
||
|
|
||
|
if (last_m != NULL) new_m->suivant = last_m;
|
||
|
last_m = new_m;
|
||
|
}
|
||
|
|
||
|
l = last_m;
|
||
|
|
||
|
list(l);
|
||
|
printf("%3hu\n", max(l));
|
||
|
return EXIT_SUCCESS;
|
||
|
}
|
||
|
|