In another thread on the C board I posted this abbreviated program:
I am now being asked to turn it into a C++ file, with one .cpp for class definition and one for testing it. However, I'm stumped as to whether my class should define a "node" or a "list."Code:#include <stdio.h> #include <stdlib.h> typedef struct nodeStruct { int data; struct nodeStruct* next; struct nodeStruct* previous; } node; node* initList(int listLength) {} int getLength(node* head) {} node* sortList(node* head) {} void printList(node* head) {} int main() {}
If I only make a class for the list, then I am still stuck with the "typedef struct" block for the node, and (a) I'm not sure where to put that block and (b) I am not sure if typedef belongs in a C++ code since class seems better.
If I only make a class for the node, then I'm performing "list methods" (print list, sort list, etc) on a node object, which doesn't seem to make sense logically.
If I make both classes, it gets pretty complex (for me, first ever C++ program), and I'm ending up with more files than asked for in the requirement.
Any advice is appreciated. I've spent a couple hours already trying to code it in multiple different ways, none of which have worked. At the very least, I need to decide WHICH path to go down and even then I will still have a lot of problems to sort out, but at least I'll be on the right track.
Thanks.



LinkBack URL
About LinkBacks



