C语言农夫过河问题( 二 )

< 16; i++)route[i] =- 1;//准备数组route初值route[0] = 0;while (!isEmptyQueue_seq(moveTo) && (route[15] ==- 1)){location = frontQueue_seq(moveTo); //取队头状态为当前状态deQueue_seq(moveTo);for (movers = 1; movers <= 8; movers <<= 1)//考虑各种物品移动if ((0 != (location &0x08)) == (0 != (location &movers)))//农夫与移动的物品在同一侧{newlocation = location ^ (0x08 | movers); //计算新状态if (safe(newlocation) && (route[newlocation] ==- 1))//新状态安全且未处理{route[newlocation] = location; //记录新状态的前驱enQueue_seq(moveTo, newlocation); //新状态入队}}}// 打印出路径if (route[15] !=- 1)//到达最终状态{printf("The reverse path is : \n");for (location = 15; location >= 0; location = route[location]){printf("The location is : %d\n", location);if (location == 0)exit(0);}}elseprintf("No solution./n");//问题无解}