Wednesday, August 17, 2011
C Code: Display word one from a linked list 1 at a time until all entries have been displayed.?
I'm not going to bother with code, but I shall suggest an algorithm. Have a ptrNode called current. Set it equal to the head of the list. Print out current->Source_Word. Enter a loop until current==NULL;. Input a character, say char. If toupper(char)=='B' set current=current->pPrev and print out current->Source_Word. If toupper(char)=='F' set current=pNext and print out current->Source_Word. if toupper(char) is anything else print out "I don't understand that". Use a switch statement instead of the three ifs. The only problem is that if you're at the head of the list and hit F you should either crash or break out of the loop. Nevertheless that seems to be how to do it.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment