Skip to content

Instantly share code, notes, and snippets.

@shrujandev
Last active November 19, 2021 03:42
Show Gist options
  • Save shrujandev/a97a286f168bb90d9ff961859254ffd0 to your computer and use it in GitHub Desktop.
Save shrujandev/a97a286f168bb90d9ff961859254ffd0 to your computer and use it in GitHub Desktop.

Revisions

  1. shrujandev revised this gist Nov 19, 2021. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions findPath.c
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    void findPath(Head * ptr, int endI, int endJ, FILE * output) {
    Stack * stack;
    Stack * stack; //struct containg a node and pointer to the same type
    int condition = 0;
    stack = (Stack * ) malloc(sizeof(Stack));
    stack = (Stack * ) malloc(sizeof(Stack)); //Mallocing the stack
    stack -> head = NULL;
    Node * move;
    Node * move; //This pointer is the one that moves and finds path
    move = ptr -> head;
    pushElement(stack, move);
    while (condition == 0) {
  2. shrujandev created this gist Nov 19, 2021.
    56 changes: 56 additions & 0 deletions findPath.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    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;
    }
    }