472,780 Members | 2,050 Online

# I've this problem: list iterator not dereferencable

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 5045
gpraghuram
1,275 Expert 1GB
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 Expert 1GB
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 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::ListNode *' with when I added List:: before... 1 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 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 > positions ; std::list >::iterator... 2 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 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 by: jayesah | last post by: Hi All, List and its iterator work as following way : list::iterator itr; itr = mylist.begin(); cout << (*itr); But I want something like this: 18 by: desktop | last post by: 1) I have this code: std::list{ 0 by: Mushico | last post by: How to calculate date of retirement from date of birth 2 by: DJRhino | last post by: Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.