Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
backtracking
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
#include<stdio.h> #define SIZE 8 int stack[SIZE*SIZE][2]; int travelled[SIZE*SIZE][2]; int stackpointer; int travelpointer; int mazeArray[SIZE][SIZE] = { {0, 0, 1, 1, 1, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 1, 1, 0, 1, 1, 1, 1}, {1, 1, 1, 0, 1, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 1, 1, 1, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 0, 0}, {1, 1, 1, 1, 1, 1, 1, 0} }; int isnotpresent(int x,int y) { printf("here"); int index; for(index=0;index<travelpointer;++index) { if(x==travelled[index][0] && y==travelled[index][1]) return 0; } for(index=0;index<stackpointer;++index) { if(x==stack[index][0] && y==stack[index][1]) return 0; } printf("here2\n"); return 1; } void init() { stackpointer =0; travelpointer =0; } void push(int i,int j) { ++stackpointer; stack[stackpointer][0]=i; stack[stackpointer][1]=j; printf("%d ",stackpointer); } int pop() { printf("%d ",stackpointer); --stackpointer; return (stackpointer+1); } int main() { char c; init(); push(0,0); int temp; while(stackpointer) { scanf("%c",&c); temp = pop(); { printf("poped %d %d \n", stack[temp][0],stack[temp][1] ); travelled[travelpointer][0]=stack[temp][0]; travelled[travelpointer][1]=stack[temp][1]; ++travelpointer; } if(stack[temp][0]==SIZE-1 && stack[temp][1]==SIZE-1) break; if(travelled[travelpointer][1]+1 != SIZE && mazeArray[travelled[travelpointer][0]+1][travelled[travelpointer][1]]==0 && isnotpresent(travelled[travelpointer][0]+1,travelled[travelpointer][1])) { printf("pushing down %d %d \n", stack[temp][0]+1,stack[temp][1]); push(stack[temp][0]+1,stack[temp][1]); } if(travelled[travelpointer][0]+1 != SIZE && mazeArray[travelled[travelpointer][0]][travelled[travelpointer][1]+1]==0 && isnotpresent(travelled[travelpointer][0],travelled[travelpointer][1]+1)) { printf("pushing right %d %d \n", stack[temp][0],stack[temp][1]+1 ); push(stack[temp][0],stack[temp][1]+1); } } while(stackpointer) { temp=pop(); printf("%d %d\n",stack[temp][0],stack[temp][1]); } }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
edit mode
|
history
|
discussion