#include #include #include #define RANGE 52 #define BALLS 6 int getBall(void); struct lotto { int ball[BALLS]; struct lotto *previous; struct lotto *next; }; struct lotto *f,*c,*n,*p,*l; int main() { int x,y; srand((unsigned)time(NULL)); /* seed randomizer */ /* fill first record */ f = (struct lotto *)malloc(sizeof(struct lotto)); for(x=0;xball[x] = getBall(); f->previous = NULL; f->next = NULL; c = f; /* fill middle records */ for(y=0;y<9;y++) { p = c; n = (struct lotto *)malloc(sizeof(struct lotto)); c->next = n; c = n; for(x=0;xball[x] = getBall(); c->previous = p; } /* fix in the last record */ c->next = NULL; l = c; /* display all records forward */ y = 1; for(c = f;c !=NULL;c=c->next) { printf("Lotto pix %d: ",y++); for(x=0;xball[x]); putchar('\n'); } /* display all the records reverse */ y = 10; for(c = l;c != NULL;c=c->previous) { printf("Lotto pix %d: ",y--); for(x=0;xball[x]); putchar('\n'); } return(0); } int getBall(void) { return(rand() % RANGE + 1); }