472,780 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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<T>::ListNode *' with when I added List<T>:: 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<std::vector<Site> > positions ; std::list<std::vector<Site> >::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<intmylist; list<int>::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<intmylist; mylist.push_back(1); mylist.push_back(2); mylist.push_back(3); mylist.push_back(4);
1
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
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
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
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.