Home > Back-end >  C write access rights conflict, p is nullptr. How to solve?
C write access rights conflict, p is nullptr. How to solve?

Time:09-15



All quick collapse, bosses give directions



Complete code for the following
 # include 
using namespace std;
#include
#include
#include
#include
Static int target [9]={7,1,3,4,8,6,5,0,2};//target state
//the class definition
The class eight_num
{
Private:
Int num [9].
Int not_in_position_num;
Int deapth;
Int eva_function;
Public:
Eight_num * parent;
Eight_num * leaf_next;
Eight_num * leaf_pre;
Eight_num (int init_num [9]);
Eight_num (int num1, int num2, int num3, int num4, int num5, int num6, int num7, int num8, int num9)
{
Num [0]=num1;
Num [1]=num2;
Num [2]=num3;
Num [3]=num4;
Num [4]=num5;
Num [5]=num6;
Num [6]=num7;
Num [7]=num8;
Num [8]=num9;
}
Eight_num (void)
{
for (int i=0; i <9. I++)
Num [I]=I;
}
Void cul_para (void);
Void get_numbers_to (int other_num [9]);
Int get_nipn (void)
{
Return not_in_position_num;
}
Int get_deapth (void)
{
Return deapth;
}
Int get_evafun (void)
{
Return eva_function;
}
Void set_num (int other_num [9]);
Void show (void);
Eight_num & amp; Operator=(eight_num & amp;);
Eight_num & amp; Operator=(int other_num [9]);
Int operator==(eight_num & amp;);
Int operator==(int other_num [9]);
};
//calculating the value of heuristic function g (n)
Void eight_num: : cul_para (void)
{
int i;
Int temp_nipn=0;
for (i=0; i <9. I++)
If (num [I]!=target [I])
Temp_nipn + +;
Not_in_position_num=temp_nipn;
If (this - & gt; The parent==NULL)
Deapth=0;
The else
Deapth=this - & gt; The parent - & gt; Deapth + 1;
Eva_function=not_in_position_num + deapth;
}
//the constructor 1
Eight_num: : eight_num (int init_num [9])
{
for (int i=0; i <9. I++)
Num=init_num [I] [I];
}

//show the status of the current node
Void eight_num: : show ()
{
Cout & lt; Cout & lt; <"";
Cout & lt; Cout & lt; <"";
Cout & lt; Cout & lt; <"\ n";
Cout & lt; Cout & lt; <"";
Cout & lt; Cout & lt; <"";
Cout & lt; Cout & lt; <"\ n";
Cout & lt; Cout & lt; <"";
Cout & lt; Cout & lt; <"";
Cout & lt; Cout & lt; <"\ n";
}
//copy of the current node state into another array
Void eight_num: : get_numbers_to (int other_num [9])
{
for (int i=0; i <9. I++)
Other_num [I]=num [I];
}
//set the current node status (to set the state of the record of other array)
Void eight_num: : set_num (int other_num [9])
{
for (int i=0; i <9. I++)
Num=other_num [I] [I];
}

Eight_num & amp; Eight_num: : operator=(eight_num & amp; Another_8num)
{
for (int i=0; i <9. I++)
Num=another_8num. [I] num [I];
Not_in_position_num=another_8num. Not_in_position_num;
Deapth=another_8num. Deapth + 1;
Eva_function=not_in_position_num + deapth;
Return * this;
}
Eight_num & amp; Eight_num: : operator=(int other_num [9])
{
for (int i=0; i <9. I++)
Num=other_num [I] [I];
Return * this;
}
Int eight_num: : operator==(eight_num & amp; Another_8num)
{
Int match=1;
for (int i=0; i <9. I++)
If (num [I]!=another_8num. Num [I])
{
Match=0;
break;
}
If (match==0)
return 0;
The else
return 1;
}
Int eight_num: : operator==(int other_num [9])
{
Int match=1;
for (int i=0; i <9. I++)
If (num [I]!=other_num [I])
{
Match=0;
break;
}
If (match==0)
return 0;
The else
return 1;
}
//the class definition over
//space moving upward
Int move_up (int num [9])
{
for (int i=0; i <9. I++)
{
If (num [I]==0)
break;
If (I & lt; 3)
return 0;
The else
{
Num=num [I] [I - 3];
Num [I - 3]=0;
return 1;
}
}
}
//space down
Int move_down (int num [9])
{
for (int i=0; i <9. I++)
{
If (num [I]==0)
break;
If (I & gt; 5)
return 0;
The else
{
Num=[I] num + 3 [I];
Num + 3 [I]=0;
return 1;
}
}
}
//space left shift
Int move_left (int num [9])
{
for (int i=0; i <9. I++)
{
If (num [I]==0)
break;
If (I==0 | | I==3 | | I==6)
return 0;
The else
{
Num=num [I] [I - 1);
Num] [I - 1=0;
return 1;
}
}
}
//space to the right move
Int move_right (int num [9])
{
for (int i=0; i <9. I++)
{
If (num [I]==0)
break;
If (I==2 | | I==5 | | I==8)
return 0;
The else
{
Num=num [I] [I + 1);
Num [I + 1)=0;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related