Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing to traverse when erasing a node using a breadth_first_queued_iterator #27

Open
t114211200 opened this issue Dec 11, 2024 · 0 comments

Comments

@t114211200
Copy link

tree<int> tr;
auto top = tr.begin();
auto root = tr.insert(top, 0);
auto a1 = tr.append_child(root, 1);
auto a2 = tr.append_child(root, 2);
auto a3 = tr.append_child(root, 3);

tr.append_child(a1, 11);
tr.append_child(a1, 12);
tr.append_child(a1, 13);

tr.append_child(a2, 21);
tr.append_child(a2, 22);
tr.append_child(a2, 23);

tr.append_child(a3, 31);
tr.append_child(a3, 32);
tr.append_child(a3, 33);

auto iter = tr.begin_breadth_first();
auto end = tr.end_breadth_first();
while (end != iter)
{
	if (*iter == 2) // erase '2'
	{
		iter = tr.erase(iter);
	}
	else
	{
		cout << *iter << endl;
		++iter; // The node '2' is still being traversed, but it has already been deleted.
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant