I am trying to remove an item in my link list. It does have 2 threads going threw it.
headByName and headByRating.
Code:
class list
{
public:
list(void); // constructor
virtual ~list(void); // destructor
void displayByName(ostream& out) const;
void displayByRating(ostream& out) const;
void insert(const winery& winery);
winery * const find(const char * const name) const;
bool remove(const char * const name);
private:
struct node
{
node(const winery& winery); // constructor
winery item;
node * nextByName;
node * nextByRating;
};
node * headByName;
node * headByRating;
};
#endif // _LIST_
What i am trying to do is remove "cooper" from the list. how can i add headByRating below so it contains all the items as headByName.
Code:
bool list::remove (const char * const name)
{
node * prev = NULL;
node * p = NULL;
node * curr = headByName;
while(curr)
{
if(strcmp(curr->item.getName(), name) == 0)
{
prev = headByName;
p = prev->nextByName;
headByName = p;
//delete prev;
return true;
}
curr = curr->nextByName;
}
return false;
Code:
cout << "\n>>> removing Cooper Mountain\n";
wineries->remove("Cooper Mountain");
I think thats all the code you would need. I just dont know how to attach the headByRating in the list with headByname in the remove function?
Thank you