I don't know why I'm having so much trouble with this. It seems like it should be easy. I have a linked list class (there are some other functions which make it more than a standard linked list, but they aren't important here). I'll paste in a simplified version of what I have. I realize that 0 can't be added to the list, but that's ok, because I don't ever need to - that is not the problem.
Yeah, I know there's a lot of commenting, more than is needed. Oh well. Any ideas on how to return the pointer to the node with the smallest value for data?Code:class linked_list { public: void adddata(int add); //adds data to the list if it is not already present int countnodes(); //counts the nodes in the list through recursion linked_list(); ~linked_list(); private: int data; linked_list *next; //pointer to the next node in the linked list linked_list *getlastnode(); // return address of last node (uses recursion) linked_list *findlow(int *min); }; linked_list::linked_list() { data=0; next=NULL; } linked_list::~linked_list() { if (next) //if next node, delete it (recursion again) delete next; } void linked_list::adddata(int add) { if (data!=add) { if (data==0) //no data in this node yet data=add; else //node contains data, and it isn't add { if (next==NULL) //no next node yet next=new linked_list; next->adddata(add); //call adddata on the next node...recursion } } } int linked_list::countnodes() { if (next) //there are more nodes return (1+ (next->countnodes()) ); //use recursion to count the nodes else return 1; //reached the end of the list } linked_list* linked_list::getlastnode() { /* This function uses recursion to get and return the address of the last node in the list */ if (next) return next->getlastnode(); else return this; } linked_list* linked_list::findlow(int *min) { /* Find the node with the lowest frequency and return a pointer to it */ if (*min>data) *min=data; /********************************************* this is what I don't know *********************************************/ return NULL; }