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

【报错】9.22 题目中,应该同时修改 mid 的值,否则也会失效 #15

Open
amwps290 opened this issue Jan 26, 2021 · 2 comments

Comments

@amwps290
Copy link

int main()
{
	vector<int> iv = { 1,2,3,4,5,6,7,8 };
	vector<int>::iterator iter = iv.begin(),
		mid = iv.begin() + iv.size() / 2;
	while (iter != mid)
	{
		if (*iter == 3)
		{
			iter = iv.insert(iter, 2 * 3);
			++iter;
			mid = iv.begin() + iv.size() / 2;
		}
		++iter;
	}

    return 0;
}
@amwps290 amwps290 changed the title 【报错】9.22 题目中,同时应该同时修改 mid 的值,否则也会失效 【报错】9.22 题目中,应该同时修改 mid 的值,否则也会失效 Jan 26, 2021
@korruz
Copy link

korruz commented Mar 13, 2021

🐮,我今天刚刚看到这里,也没注意,vscode运行也没报错,后面我在 for 循环里 加上 cout << __LINE__ << endl;,发现会一直循环,后面 vscode 自动结束循环了

@fengxi1
Copy link

fengxi1 commented Apr 3, 2022

这么写的话mid也在跟着后移吧

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

3 participants