In the loop im feeding the head node into a sorting function that I have defined and then im using strcmp to find out which name in the node should come first. We Find that name and print that node.

But Their is a problem, the node that is the least_found_node will be ALWAYS be the least_found_node...Is removing it the only option?

I cant assign it to NULL b/c the loop will end terminate.

The two functions that are most important to me now are defined as follows: I have tried my best to do what I think is right for the sorting function.

void list::displayByName(ostream& out) const { node *current_node = headByName; node *returned_node = NULL; while ( current_node != NULL ) { current_node = sort( current_node ); out << current_node->item.getName() << endl; } }

list::node * const list::sort( node *given_node ) const { node *least_found_node = NULL; node *current_node = given_node->nextByName; while ( current_node && current_node != given_node ) { if ( strcmp( current_node->item.getName(), given_node->item.getName() ) < 0 ) { // Is this node smaller than the smallest node we know of? if ( least_found_node == NULL || ( strcmp( least_found_node->item.getName(), current_node->item.getName() ) > 0 ) ) { // we found a better node! least_found_node = current_node; } } current_node = current_node->nextByName; } return least_found_node; }

And I started to develop my nodes here: BTW, the winery below is a class object type completely seperate from the class list and the struct node.

void list::insert(const winery& winery) { node *current_node = new node( winery ); if ( headByName == NULL ) { headByName = current_node; headByRating = current_node; tail = headByName; current_node->prev = current_node; } else { current_node->prev = tail; tail->nextByName = current_node; } tail = current_node; current_node = NULL; }

I think its correct in that function above. Could I possible get a way with sorting it their? One question at a time right? hehe.

A correct working remove function. ( I can remove the tail and head with no crash )

bool list::remove (const char * const name) { node *current = headByName; while ( current != NULL ) { if ( strcmp( name, current->item.getName() ) != 0 ) current = current->nextByName; else {//this must be the one. if ( current == headByName ) { current = current->nextByName; headByName->prev = NULL; return true; } else if ( current == tail ) { tail = tail->prev; tail->nextByName = NULL; return true; } else { current->prev->nextByName = current->nextByName; current->nextByName->prev = current->prev; return true; } } } return false; }

Skipping over the node is a possibility. But I have tried calling this function where appropriate (lol) and i get a crash because of the second assignment in the function above. current = head.

Anyways below are my varaibles that I am working with:

public list { ... void insert(const winery& winery); void displayByName(ostream& out) const; } private: struct node { node(const winery& winery); // constructor winery item; node * prev; node * nextByName; node * nextByRating; }; winery * const sort(node*) const; node * headByName; node * headByRating; node * tail; };

Any help is appreciated. Thanks very much =)

This post has been edited by **array**: 05 September 2009 - 04:40 PM