path.c/h: consistent indentation

This commit is contained in:
wdlkmpx 2021-01-14 22:13:53 +08:00
parent 3588163047
commit 7461795c1b
2 changed files with 89 additions and 80 deletions

View File

@ -49,13 +49,15 @@ int find_node_by_coords(int x, int y, int number_of_x_cells, int number_of_y_cel
number_of_cells: number of cells in the row
returns number of marked nodes */
int mark_neighbours_of_the_nodes (int *nodes, int *source_nodes, int *neighbours, int mark,
int number_of_x_cells, int number_of_y_cells) {
int number_of_x_cells, int number_of_y_cells)
{
int i, j, neighbours_count = 0;
int x, y, node;
int xses[4] = { 0, 0, 1, -1};
int yses[4] = {-1, 1, 0, 0};
for(i = 1; i <= source_nodes[0]; i++) {
for (i = 1; i <= source_nodes[0]; i++)
{
find_x_y_of_the_node(&x, &y, source_nodes[i], number_of_x_cells, number_of_y_cells);
if (x != -1 && y != -1) {
for (j = 0; j < 4; j++) {
@ -75,7 +77,8 @@ int mark_neighbours_of_the_nodes(int *nodes, int *source_nodes, int *neighbours,
}
/* check if nodes are neighbours */
int is_neighbours(int node1, int node2, int xn, int yn) {
int is_neighbours(int node1, int node2, int xn, int yn)
{
int x1, y1, x2, y2;
find_x_y_of_the_node(&x1, &y1, node1, xn, yn);
@ -89,11 +92,13 @@ int is_neighbours(int node1, int node2, int xn, int yn) {
return 0;
}
/* find the path between source_node and the target_node
result stored in path
returns 0 on failure and 1 on success */
int find_path (int *nodes, int source_node, int target_node, int *path,
int number_of_x_cells, int number_of_y_cells) {
int number_of_x_cells, int number_of_y_cells)
{
int waves[number_of_x_cells * number_of_y_cells][number_of_x_cells * number_of_y_cells];
int i, j, k = 1, finish = 0;
@ -101,7 +106,8 @@ int find_path(int *nodes, int source_node, int target_node, int *path,
waves[0][1] = source_node;
nodes[source_node] = -1;
while(!finish) {
while (!finish)
{
if (!mark_neighbours_of_the_nodes(nodes, waves[k - 1], waves[k], k,
number_of_x_cells, number_of_y_cells)) {
/* the destination can never be reached */
@ -118,7 +124,8 @@ int find_path(int *nodes, int source_node, int target_node, int *path,
path[0] = k;
path[1] = waves[k - 1][i];
for(j = k - 2; j > 0; j--) {
for (j = k - 2; j > 0; j--)
{
finish = 0;
for (i = 1; i <= waves[j][0]; i++) {
if (is_neighbours(waves[j][i], path[k - j - 1],

View File

@ -3,8 +3,10 @@
int find_path (int *nodes, int source_node, int target_node, int *path,
int number_of_x_cells, int number_of_y_cells);
void find_x_y_of_the_node (int *x, int *y,
int node, int number_of_x_cells, int number_of_y_cells);
int find_node_of_x_y (int x, int y, int number_of_x_cells);
#endif