473,480 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

I've this problem: list iterator not dereferencable

1 New Member
Hello guys, I have a problem with this code, the program is the resolution of Sudoku grid, the grid in my program is a vector of STL,and i use a list of STL for the right solution for each cell, to solve my grid i call recursive the function : void risolvi(int indice).
The problem i have is about the iterator, but i don't know how i can fix it, i need your help.
This problem blocks me to come back in to the main function, and so i can't output my solution.
Thank you, and sorry for my bad english

Expand|Select|Wrap|Line Numbers
  1. void risolvi(int indice)
  2. {
  3.     list<int> SOLUZIONI;
  4.     list<int >::iterator scorri;
  5.     list<int >::iterator scendi;
  6.     if(indice==81)
  7.     {
  8.  
  9.         vector<int>::iterator scorrimento;
  10.         for(scorrimento=VETTORE.begin(); scorrimento!=VETTORE.end(); scorrimento++)
  11.             cout<<*scorrimento<<endl;        
  12.         cout<<"THE END"<<endl;
  13.     }
  14.     else
  15.     {
  16.         if(verita[indice])
  17.             risolvi(indice+1);
  18.         else
  19.         {
  20.             //list<int> SOLUZIONI;
  21.             for(int s=1;s<=9;s++)
  22.                 SOLUZIONI.push_back(s);
  23.             int riga = indice/9, colonna = indice%9;
  24.             int imin = (riga/3)*3;
  25.             int jmin = (colonna/3)*3;
  26.             //ELIMINO GLI ELEMENTI GIA' PRESENTI NEL CUBO 3x3
  27.             for(int rig=imin ; rig < imin+3 ; rig++)
  28.             {
  29.                 for(int colonna=jmin ; colonna < jmin+3 ; colonna++)
  30.                     if(VETTORE[9*rig+colonna]!=0)
  31.                         SOLUZIONI.remove(VETTORE[9*rig+colonna]);
  32.             }
  33.             //ELIMINO GLI ELEMENTI GIA' PRESENTI NELLA RIGA
  34.             for(int i=indice%9;i<=(indice%9)+72;i=i+9)
  35.                 if(VETTORE[i]!=0)
  36.                     SOLUZIONI.remove(VETTORE[i]);
  37.             //ELIMINO GLI ELEMENTI GIA' PRESENTI NELLA COLONNA
  38.             for(int m=indice/9*9;m<(indice/9*9)+8;m++)
  39.                 if(VETTORE[m]!=0)
  40.                     SOLUZIONI.remove(VETTORE[i]);
  41.             //ELIMINA LA PRIMA SOLUZIONE CHE HO CONSIDERATO AL PASSO PRECEDENTE
  42.             //MA CHE IL BACKTRACKING MI HA VALUTATO ERRATA            
  43.             if(backtracking!=appoggio&&SOLUZIONI.size()!=0)
  44.             {
  45.                 //list<int>::const_iterator scendi;
  46.                 scendi=SOLUZIONI.begin();
  47.                 while(*scendi<=numero&&SOLUZIONI.size()!=0)
  48.                 //while(SOLUZIONI[1]<=numero && SOLUZIONI.size()!=0)
  49.                     {
  50.                         scendi++;
  51.                         SOLUZIONI.pop_front();
  52.                         if(SOLUZIONI.size()==0)
  53.                         {
  54.                             appoggio=backtracking;
  55.                             do
  56.                             {
  57.                                 if(!verita[indice])
  58.                                     VETTORE[indice]=0;
  59.                                 indice--;
  60.                             }
  61.                             while(verita[indice]);
  62.                             numero=VETTORE[indice];
  63.                             backtracking++;
  64.                             risolvi(indice);
  65.                         }
  66.                     }            
  67.                     appoggio=backtracking;
  68.             }
  69.             scorri=SOLUZIONI.begin();
  70.             if(SOLUZIONI.size()!=0)
  71.             {
  72.                 VETTORE[indice]=*scorri;
  73.                 //if (indice==79)
  74.                 //    return;
  75.                 risolvi(indice+1);
  76.             }        
  77.             else
  78.             {
  79.                 appoggio=backtracking;
  80.                 do
  81.                 {
  82.                     if(!verita[indice])
  83.                         VETTORE[indice]=0;
  84.                     indice--;
  85.                 }
  86.                 while(verita[indice]);
  87.                 numero=VETTORE[indice];
  88.                 backtracking++;
  89.                 risolvi(indice);
  90.             }
  91.         }
  92.     }
  93.  
  94. }
Jan 8 '08 #1
2 5098
gpraghuram
1,275 Recognized Expert Top Contributor
Hi,
In which line you get the error.
I acnt compile the code locally as some of the declarations are missing.
So post the remaining part of the code so that i can compile and see why the problem is coming

NOTE:
Please use code tags while posting the code

Thanks
Raghuram
Jan 9 '08 #2
Savage
1,764 Recognized Expert Top Contributor
Hi,
In which line you get the error.
I acnt compile the code locally as some of the declarations are missing.
So post the remaining part of the code so that i can compile and see why the problem is coming

NOTE:
Please use code tags while posting the code

Thanks
Raghuram
I believe that this is that line:

Expand|Select|Wrap|Line Numbers
  1. while(*scendi<=numero&&SOLUZIONI.size()!=0)
,but i don't see any reason for this to not compile.
Jan 9 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1735
by: darkstorm | last post by:
Hi, Please have a look at this code when compiling it is giving error: error C2440: '=' : cannot convert from 'ListNode *' to 'List<T>::ListNode *' with when I added List<T>:: before...
1
2112
by: darkstorm | last post by:
Please check this program...When I compiles it in VC.net, it gives the following error: =============== Common\Lib\PList.h(115): error C2440: '=' : cannot convert from 'ListNode *' to...
13
4888
by: Adam Hartshorne | last post by:
Hi All, I was wondering if anybody can tell me what is wrong with the following code, in a .h file I have std::list<std::vector<Site> > positions ; std::list<std::vector<Site> >::iterator...
2
1545
by: weatherman | last post by:
Dear all, When porting some code from g++ 2.95/3.2 to g++ 4.01 we encountered some difficulties with the following construction. The code is known to compile on g++ 2.95 and g++ 3.2.2. This...
7
1906
by: PengYu.UT | last post by:
I'm wondering is the standard defined behavior of past bound iterator. In the following example it seems that afer first "--it", it point to -1 index. I'm wondering if it is true independent of...
15
2762
by: jayesah | last post by:
Hi All, List and its iterator work as following way : list<intmylist; list<int>::iterator itr; itr = mylist.begin(); cout << (*itr); But I want something like this:
18
2089
by: desktop | last post by:
1) I have this code: std::list<intmylist; mylist.push_back(1); mylist.push_back(2); mylist.push_back(3); mylist.push_back(4);
1
6219
by: David Bilsby | last post by:
All Apologies for cross posing this but I am not sure if this is a VC 8 STL bug or simply an invalid use of the iterator. I have a PCI card access class which basically abstracts a third party...
1
1627
by: ashishbhatt12 | last post by:
Hi All, I am using list class in my project(MFC Application). I have made list like ..... typedef std::list rectlist; // Here list is of type RECT in one header file. And during my project...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7048
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
7088
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
6956
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
5342
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,...
1
4783
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
183
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.