Last active
          November 19, 2021 03:42 
        
      - 
      
- 
        Save shrujandev/a97a286f168bb90d9ff961859254ffd0 to your computer and use it in GitHub Desktop. 
    Path finding Code for Rat in a Maze 
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | void findPath(Head * ptr, int endI, int endJ, FILE * output) { | |
| Stack * stack; | |
| int condition = 0; | |
| stack = (Stack * ) malloc(sizeof(Stack)); | |
| stack -> head = NULL; | |
| Node * move; | |
| move = ptr -> head; | |
| pushElement(stack, move); | |
| while (condition == 0) { | |
| if (move -> i < endI && move -> j < endJ) { | |
| if (move -> right -> data == 0) { | |
| move = move -> right; | |
| pushElement(stack, move); | |
| } | |
| else if (move -> down -> data == 0) { | |
| move = move -> down; | |
| pushElement(stack, move); | |
| } | |
| else if (move -> down -> data != 0 && move -> right -> data != 0) { | |
| move -> data = 1; | |
| move = popElement(stack); | |
| } | |
| } | |
| else if (move -> i == endI && move -> j != endJ) { | |
| if (move -> right -> data == 0) { | |
| move = move -> right; | |
| pushElement(stack, move); | |
| } | |
| else if (move -> down -> data != 0 && move -> right -> data != 0) { | |
| move -> data = 1; | |
| move = popElement(stack); | |
| } | |
| } | |
| else if (move -> i != endI && move -> j == endJ) { | |
| if (move -> down -> data == 0) { | |
| move = move -> down; | |
| pushElement(stack, move); | |
| } | |
| else if (move -> down -> data != 0 && move -> right -> data != 0) { | |
| move -> data = 1; | |
| move = popElement(stack); | |
| } | |
| } | |
| else { | |
| condition = 1; | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
This is the path finding function that is present in the Rat-in-the-Maze repository