Home > Back-end >  What a great god can help me have a look
What a great god can help me have a look

Time:09-25

This program is always running out, please everyone a great god help see
# include
# include
# include
//15 digital state corresponding to the node structure
Struct Node {
Int s [4] [4];//save fifteen digital state, 0 Spaces
Int f, g;//inspired in the function f and g values
Struct Node * next;
Struct Node * previous;//save the father node
};
Int open_N=0;//record of node number in the Open list
//15 digital initial state
Int inital_s [4] [4]={
2,3,5,9,
1,4,10,12,
7,0,11,8,
6,13,14,15
};
//15 digital target state
Int final_s [4] [4]={
1, 2, 3, 4,
12,13,14,5,
11,0,15,6,
10,9,8,7
};
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//add node function entry, method: through to the designated table insertion sort add
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void Add_Node (struct Node * head, struct Node * p)
{
Struct Node * q;
If (the head - & gt; Next)//considered linked list is empty
{
Q=head - & gt; Next;
If (p - & gt; F & lt; The head - & gt; Next - & gt; F) {//consider inserting node value is smaller than list the first node values
P - & gt; Next=head - & gt; Next; The head - & gt; Next=p;
}
The else {
While (q - & gt; Next)//consider inserting node x, like a<=x & lt;=b
{
If ((q - & gt; F & lt; P - & gt; F | | q - & gt; F==p - & gt; F) & amp; & (q - & gt; Next - & gt; F & gt; P - & gt; F | | q - & gt; Next - & gt; F==p - & gt; F)) {
P - & gt; Next=q - & gt; Next;
Q - & gt; Next=p;
break;
}
Q=q - & gt; Next;
}
If (q - & gt; Next==NULL)//consider inserting node value than list the last element of a larger
Q - & gt; Next=p;
}
}
The else head - & gt; Next=p;
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//delete node function entry
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void del_Node (struct Node * head, struct Node * p) {
Struct Node * q;
Q=head;
While (q - & gt; Next)
{
If (q - & gt; Next==p) {
Q - & gt; Next=p - & gt; Next;
P - & gt; Next=NULL;
If (q - & gt; Next==NULL) return;
//free (p);
}
Q=q - & gt; Next;
}
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//determine whether two arrays is equal function entry
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Int equal (int s1 [4], [4], int s2 [4] [4])
{
Int I, j, flag=0;
For (I=0; i <4. I++)
For (j=0; J & lt; 4. J++)
If (s1 [I] [j].=s2 [I] [j]) {flag=1; break; }
if (! Flag)
return 1;
The else return 0;
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//whether the subsequent nodes exist in the Open or Closed function entry in the table
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Int exit_Node (struct Node * head, int s [4], [4], struct Node * Old_Node) {
Struct Node * q=head - & gt; Next;
Int flag=0;
While (q)
If (equal (q - & gt; S, s)) {
Flag=1;
Old_Node - & gt; Next=q;
return 1;
}
The else q=q - & gt; Next;
if (! Flag) return 0;
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//calculate p (n) function entry
//dislocation of p (n) for the sum of the distance between the digital and its correct position
//specific methods: dislocation of digital and its correct position corresponding to the sum of the absolute value of difference subscript
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Int wrong_sum (int s [4] [4])
{
Int I, j, fi, fj, sum=0;
For (I=0; i <4. I++)
For (j=0; J & lt; 4. J++)
{
For (fi=0; Fi & lt; 4. Fi++)
For (fj=0; Fj: & lt; 4. Fj++)
If ((final_s [fi] [fj] [I] [j])==s) {
The sum +=fabs (I - fi) + fabs (j - fj);
break;
}
}
return sum;
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
//function entry for subsequent nodes
//check the legitimacy of the Spaces each mobile, if the legal the mobile space for subsequent node
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Int get_successor (struct Node * BESTNODE, int direction, struct Node * Successor)//extension BESTNODE, produce its successive Node Successor
{
Int I, j, i_0, j_0, temp.
For (I=0; i <4. I++)
For (j=0; J & lt; 4. J++)
Successor - & gt; S [I] [j]=BESTNODE - & gt; S [I] [j];
//to get space location
For (I=0; i <4. I++)
For (j=0; J & lt; 4. J++)
If (BESTNODE - & gt; S [I] [j]==0) {i_0=I; J_0=j; break; }
The switch (direction)
{
Case 0: if (i_0 (1) & gt; 1) {
Temp=Successor - & gt; S [i_0] [j_0];
Successor - & gt; S [i_0] [j_0]=Successor - & gt; S [i_0-1] [j_0];
Successor - & gt; S [i_0-1] [j_0]=temp;
return 1;
}
The else return 0;
Case 1: if ((j_0-1) & gt; 1) {
Temp=Successor - & gt; S [i_0] [j_0];
Successor - & gt; S [i_0] [j_0]=Successor - & gt; S [i_0] [j_0-1);
Successor - & gt; S [i_0] [] j_0-1=temp;
return 1;
}
The else return 0;
Case 2: if (+ 1) (j_0 & lt; 4) {
Temp=Successor - & gt; S [i_0] [j_0];
Successor - & gt; S [i_0] [j_0]=Successor - & gt; S [i_0] [j_0 + 1];
Successor - & gt; S [i_0] [j_0 + 1)=temp;
return 1;
}
The else return 0;
Case 3: if (i_0 (+ 1) & lt; 4) {
Temp=Successor - & gt; S [i_0] [j_0];
Successor - & gt; S [i_0] [j_0]=Successor - & gt; S [i_0 + 1] [j_0];
Successor - & gt; S [i_0 + 1] [j_0]=temp;
return 1;
}
The else return 0;
}
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related