-
Printing linked lists
I'm almost finished with a program that uses linked lists to keep track of students and their courses.
Were supposed to print out the course part of the output in a transcript like fashion, (two courses per row).
So you'd have like:
Code:
CS2200 CIS3995
C programming Data Structures
A B
The student records are printed out using a for loop. And the course records themselves are in a nested for loop. So far, I can get the courses to print underneath each other, but our teacher wants the courses printed as above.
Any Ideas?
-
you could do something like this...
printf("%s\t%s\n",list->class,list->next->class);
list = list->next->next
just an idea.. of course you'd need to check to make sure the next node exists and all that. tell me if that works
-
Code:
*left, *right;
for( left = list, right = left->next ? left->next : NULL ; left; )
{
printf("%d", left->number )
if ( right ) printf("\tabbing\spacing%d", right->number );
...do the same for other values...
left = right ? right->next : right;
}
That should suffice.
Quzah.