473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

infinite stl list loop

Dear all,

I am just using a list<intiterator in a for loop to get the all
values in the list, like this:

for (list<int>::iterator
itt=labelLists[labels3X3cube[*iter]-1].begin();
itt!=labelLists[labels3X3cube[*iter]-1].end(); itt++ )
{

std::cout << labelLists[labels3X3cube[*iter]-1].size() <<
"___"<< (*itt) << "___" <<
*(labelLists[labels3X3cube[*iter]-1].end())<< std::endl;
si10 = labelLists[labels3X3cube[*iter]-1].size();
labels3X3cube[*itt] = currentLabel;

}
and write the size of the list __ present value ___ and the end value
of the list.
The values are like this:

4___26___0
4___25___0
3___23___6316800
3___17___6316800
3___0___6316800
3___26___6316800
3___25___6316800
3___23___6316800
3___17___6316800
3___0___6316800
3___26___6316800
3___25___6316800
3___23___6316800
3___17___6316800
3___0___6316800
....

and it repeats this pattern infinitely.

In the forloop i do not make any change in the list but something
happens. Can anyone help me in solving this problem.
Thanks in advance

burak

Oct 5 '07 #1
4 2521
I forgot to tell you the labelLists structure.
it is defined as

vector< list< int labelLists;

burak

Oct 5 '07 #2
On 5 íj, 11:03, boguz <bozkala...@gmail.comwrote:
Dear all,

I am just using a list<intiterator in a for loop to get the all
values in the list, like this:

for (list<int>::iterator
itt=labelLists[labels3X3cube[*iter]-1].begin();
itt!=labelLists[labels3X3cube[*iter]-1].end(); itt++ )
{

std::cout << labelLists[labels3X3cube[*iter]-1].size() <<
"___"<< (*itt) << "___" <<
*(labelLists[labels3X3cube[*iter]-1].end())<< std::endl;
si10 = labelLists[labels3X3cube[*iter]-1].size();
labels3X3cube[*itt] = currentLabel;

}

and write the size of the list __ present value ___ and the end value
of the list.
The values are like this:

4___26___0
4___25___0
3___23___6316800
3___17___6316800
3___0___6316800
3___26___6316800
3___25___6316800
3___23___6316800
3___17___6316800
3___0___6316800
3___26___6316800
3___25___6316800
3___23___6316800
3___17___6316800
3___0___6316800
...

and it repeats this pattern infinitely.

In the forloop i do not make any change in the list but something
happens. Can anyone help me in solving this problem.
Thanks in advance

burak
Hi.

- If you are not changing anything, use const_iterator for walking
through container.
- I do not like much line labels3X3cube[*itt] = currentLabel; Are you
sure it is correct? I think it may change something.
- When you are incrementing iterator, use prefix notation ++it instead
of it++, it may be more effective and you will save some work to
compiler

*(labelLists[labels3X3cube[*iter]-1].end())

- Dereferencing end() is not a good idea - it is iterator pointing
beyond last valid element

Ondrej

Oct 5 '07 #3
On Oct 5, 6:03 pm, boguz <bozkala...@gmail.comwrote:
for (list<int>::iterator
itt=labelLists[labels3X3cube[*iter]-1].begin();
itt!=labelLists[labels3X3cube[*iter]-1].end(); itt++ )
{
std::cout << labelLists[labels3X3cube[*iter]-1].size() <<
"___"<< (*itt) << "___" <<
*(labelLists[labels3X3cube[*iter]-1].end())<< std::endl;
si10 = labelLists[labels3X3cube[*iter]-1].size();
labels3X3cube[*itt] = currentLabel;

}

and it repeats this pattern infinitely.

burak
To sort these kind of things out, you've can work things from either
(or needs be both) ends: gradually simplify until things start
working, or take something absolutely simple (a test program iterating
over a list) and make it gradually more complex (like your broken
code), until you see what breaks it too. It's a skill and discipline
you'll need to write any significant software.

Here, the easiest and most pressing simplification will also help you
understand the problem (and fix it):

list<int>& ints = labelLists[labels3X3cube[*iter]-1];

Work this through, simplifying things. Think about what each line is
trying to. For example, the loop is meant to iterate over the list
you've identified above.

for (list<int>::iterator
itt=ints.begin(); itt!=ints.end(); itt++ )
{
...

Then you should find things work. What was going wrong before?
You'll find, in this case and most, that it's the line where you
_change_ something that breaks something...
labels3X3cube[*itt] = currentLabel;
Me thinks you were blatting over the numbers providing the index to
keep you iterating in the "current" list...

Tony

Oct 5 '07 #4
On Oct 5, 12:31 pm, Ondra Holub <ondra.ho...@post.czwrote:
On 5 íj, 11:03, boguz <bozkala...@gmail.comwrote:
*(labelLists[labels3X3cube[*iter]-1].end())

- Dereferencing end() is not a good idea - it is iterator pointing
beyond last valid element
I think he just meant 'rbegin'(read reverse begin):

*(labelLists[labels3X3cube[*iter]-1].rbegin())

regards,
FM.

Oct 5 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
5
by: titan0111 | last post by:
Hi, it's me again. Thank you guys for helping me with other error messages. This is the source code. It goes throught compiler fine but when I run it, it seems to be in infinite loop.
5
by: mailpitches | last post by:
Hello, Is there any way to kill a Javascript infinite loop in Safari without force-quitting the browser? MP
7
by: vjay | last post by:
I want to just create a linklist.The program below goes into an endless loop.The srange behaviour is that i can exit from the program if i create only two nodes.After two goes into infinite loop. ...
5
by: Allerdyce.John | last post by:
Hi, I have this piece of code which loops thru a STL list, but that causs an infinite loop. bool Executer::group(MyList& bl, ResultList & grl) { for (ExecuterList::iterator i =...
44
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.