468,490 Members | 2,611 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,490 developers. It's quick & easy.

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 4710
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

Post your reply

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

Similar topics

3 posts views Thread by darkstorm | last post: by
1 post views Thread by darkstorm | last post: by
13 posts views Thread by Adam Hartshorne | last post: by
15 posts views Thread by jayesah | last post: by
18 posts views Thread by desktop | last post: by
1 post views Thread by ashishbhatt12 | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.