Help Understanding Vague Assignment

Pages: 12
Ok now that I've removed Node from it, it works. I swear I'd lose my head if it wasn't attached.
Looking at the remove_all(const int& entry) now. The only hint the professor gave was this:

// Cases to look for (provided by Professor)
// head == entry
// head != entry
// middle == entry
// middle != entry

Your professor doesn't seem too bright. Either that, or he's going by the book; you don't need cases:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void list::remove_all(const int& entry)
{
    Node** temp1 = &head;

    while (*temp1 != nullptr)
    {
        if ((*temp1)->data == entry)
        {
            Node* temp2 = (*temp1)->next;
            delete *temp1;
            *temp1 = temp2;
        }
        else
        {
            temp1 = &(*temp1)->next;
        }
    }
}

I tested this by hand only, but I'm certain it works well.
I'm actually doing this same assignment for this class. I have a question on the Is_item function in the Iterator.

1
2
3
4
5
6
7
bool Iterator::is_item()
{
	if(n->next != nullptr)
		return true;
	
	return false;
}


This is what i have which works except it makes the last node in the list not an item. So if I insert 1 , 2 , 3 it prints 3 and then 2 but not the 1 as it is not an item. How would I include the last node and have the iterator stop at the end of the list?
Last edited on
Do this with pencil and paper first, guys! You will quickly see that

1
2
3
4
bool Iterator::is_item()
{
    return n != nullptr;
}

solves it.
Oh i see my mistake check the pointer itself not the next. thanks for the help
I'm under the impression that he gave you this, and it was supposed to be functional...

Seriously, your PROFESSOR wrote this?????

I think you should seriously question his credentials if he is telling you to use this for your projects.
Topic archived. No new replies allowed.
Pages: 12