Skip to content

Commit 45c6586

Browse files
committed
Commit before netlify push
1 parent b97c6b5 commit 45c6586

50 files changed

Lines changed: 1915 additions & 109 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
"homepage": "http://tamimehsan.github.io/Pathfinder-2.0",
55
"private": true,
66
"dependencies": {
7+
"@material-ui/icons": "^4.9.1",
78
"@testing-library/jest-dom": "^5.11.5",
89
"@testing-library/react": "^11.1.0",
910
"@testing-library/user-event": "^12.1.10",
1011
"bootstrap": "^4.5.3",
12+
"fontsource-roboto": "^3.0.3",
1113
"react": "^17.0.1",
1214
"react-dom": "^17.0.1",
1315
"react-router-dom": "^5.2.0",

public/_redirects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* /index.html 200

src/App.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {BrowserRouter as Router, Switch, Route} from 'react-router-dom';
33
import Pathfinder from "./pathfinderComponents/pathfinder";
44
import Home from "./homeComponents/home";
55
import Seive from "./primeComponents/seive";
6+
import Sort from "./sortComponents/sort";
7+
import Queen from "./queenComponents/queen";
68

79
class App extends Component {
810
constructor() {
@@ -16,9 +18,11 @@ class App extends Component {
1618
return (
1719
<Router>
1820
<Switch>
19-
<Route path='/Pathfinder-2.0/' exact component={Home}/>
2021
<Route path='/Pathfinder-2.0/pathfinder' component={Pathfinder}/>
2122
<Route path='/Pathfinder-2.0/prime' component={Seive}/>
23+
<Route path='/Pathfinder-2.0/sort' component={Sort}/>
24+
<Route path='/Pathfinder-2.0/nqueen' component={Queen}/>
25+
<Route path='/Pathfinder-2.0/' component={Home}/>
2226
</Switch>
2327
</Router>
2428
);

src/algorithms/recursiveMaze.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
export function getMaze(board,row,col){
2+
const pairs = [];
3+
let newBoard = board.slice();
4+
for( let i = 0;i <col;i++){
5+
newBoard[0][i].isWall = true;
6+
pairs.push({
7+
xx:0,
8+
yy:i
9+
});
10+
}
11+
for( let i = 0;i <row;i++){
12+
newBoard[i][col-1].isWall = true;
13+
pairs.push({
14+
xx:i,
15+
yy:col-1
16+
});
17+
}
18+
for( let i = col-1;i>=0;i-- ){
19+
newBoard[row-1][i].isWall = true;
20+
pairs.push({
21+
xx:row-1,
22+
yy:i
23+
});
24+
}
25+
for(let i = row-1;i>=0;i--){
26+
newBoard[i][0].isWall = true;
27+
pairs.push({
28+
xx:i,
29+
yy:0
30+
});
31+
}
32+
decideMaze(pairs,newBoard,1,row-2,1,col-2);
33+
console.log("here");
34+
return pairs;
35+
}
36+
let val = 0;
37+
38+
function decideMaze(pairs,board,startRow,endRow,startCol,endCol) {
39+
console.log("count");
40+
val++;
41+
42+
if( ((endRow-startRow) <=1) && ((endCol - startCol) <=1) ){
43+
return;
44+
}
45+
46+
if( (endCol - startCol) > (endRow - startRow) ){
47+
recursiveMazeVertical(pairs,board,startRow,endRow,startCol,endCol);
48+
} else{
49+
recursiveMazeHorizontal(pairs,board,startRow,endRow,startCol,endCol);
50+
}
51+
}
52+
function recursiveMazeVertical(pairs,board,startRow,endRow,startCol,endCol){
53+
let mid = Math.floor((endCol+startCol)/2);
54+
let random = Math.floor(Math.random() * (endRow-startRow+1)) + startRow;
55+
console.log( "row ",random," ",startRow," ",endRow );
56+
let start = startRow;
57+
if( !board[startRow-1][mid].isWall ){
58+
random = start;
59+
start++;
60+
}
61+
let end = endRow;
62+
if( !board[endRow+1][mid].isWall ){
63+
random = end;
64+
end--;
65+
}
66+
for(let i = start;i<=end;i++){
67+
if( i!==random ){
68+
board[i][mid].isWall = true;
69+
pairs.push({
70+
xx:i,
71+
yy:mid
72+
});
73+
}
74+
}
75+
decideMaze(pairs,board,startRow,endRow,startCol,mid-1);
76+
decideMaze(pairs,board,startRow,endRow,mid+1,endCol);
77+
}
78+
function recursiveMazeHorizontal(pairs,board,startRow,endRow,startCol,endCol){
79+
let mid = Math.floor((endRow+startRow)/2);
80+
// console.log("mid: ",mid);
81+
let random = Math.floor(Math.random() * (endCol-startCol+1)) + startCol;
82+
let start = startCol;
83+
if( !board[mid][startCol-1].isWall ){
84+
random = start;
85+
start++;
86+
}
87+
let end = endCol;
88+
if( !board[mid][endCol+1].isWall ){
89+
random = end;
90+
end--;
91+
}
92+
for(let i = start;i<=end;i++){
93+
if( i!==random ){
94+
board[mid][i].isWall = true;
95+
pairs.push({
96+
xx:mid,
97+
yy:i
98+
});
99+
}
100+
}
101+
decideMaze(pairs,board,startRow,mid-1,startCol,endCol);
102+
decideMaze(pairs,board,mid+1,endRow,startCol,endCol);
103+
104+
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
export function bubbleSort2(rects ){
2+
const pairs = [];
3+
const num = rects.length;
4+
const prevRect = rects.slice();
5+
6+
for( let i = 0; i<num; i++ ){
7+
for( let j = i+1;j<num;j++ ){
8+
if( prevRect[i].width>prevRect[j].width ){
9+
const recti = {...prevRect[i]};
10+
const rectj = {...prevRect[j]};
11+
prevRect[j] = recti;
12+
prevRect[i] = rectj;
13+
pairs.push( {
14+
xx:i,
15+
yy:j,
16+
changed:true
17+
} );
18+
} else{
19+
pairs.push( {
20+
xx:i,
21+
yy:j,
22+
changed:false
23+
});
24+
}
25+
if( j === num-1 ){
26+
pairs.push( {
27+
xx:i,
28+
yy:i,
29+
changed:false
30+
});
31+
}
32+
}
33+
}
34+
return pairs;
35+
}
36+
37+
export function selectionSort(arr) {
38+
const pairs = [];
39+
let n = arr.length;
40+
const prevRect = arr.slice();
41+
// One by one move boundary of unsorted subarray
42+
for (let i = 0; i < n-1; i++)
43+
{
44+
let min_idx = i;
45+
for (let j = i+1; j < n; j++){
46+
pairs.push( {
47+
xx:min_idx,
48+
yy:j,
49+
changed:false
50+
} );
51+
if (prevRect[j].width < prevRect[min_idx].width){
52+
min_idx = j;
53+
}
54+
}
55+
56+
// Swap the found minimum element with the first
57+
// element
58+
const recti = {...prevRect[i]};
59+
const rectj = {...prevRect[min_idx]};
60+
prevRect[min_idx] = recti;
61+
prevRect[i] = rectj;
62+
pairs.push( {
63+
xx:min_idx,
64+
yy:i,
65+
changed:true
66+
} );
67+
pairs.push( {
68+
xx:i,
69+
yy:i,
70+
changed:false
71+
});
72+
}
73+
pairs.push({
74+
xx:n-1,
75+
yy:n-1,
76+
changed:false
77+
}
78+
)
79+
return pairs;
80+
}
81+
82+
export function bubbleSort(arr){
83+
const pairs= [];
84+
let n = arr.length;
85+
const prevRect = arr.slice();
86+
for (let i = 0; i < n-1; i++){
87+
for (let j = 0; j < n-i-1; j++){
88+
if (prevRect[j].width > prevRect[j+1].width) {
89+
// swap arr[j+1] and arr[j]
90+
const recti = {...prevRect[j]};
91+
const rectj = {...prevRect[j+1]};
92+
prevRect[j+1] = recti;
93+
prevRect[j] = rectj;
94+
pairs.push( {
95+
xx:j,
96+
yy:j+1,
97+
changed:true
98+
} );
99+
} else{
100+
pairs.push( {
101+
xx:j,
102+
yy:j+1,
103+
changed:false
104+
} );
105+
}
106+
if( j === n-i-2 ){
107+
pairs.push( {
108+
xx:n-i-1,
109+
yy:n-i-1,
110+
changed:false
111+
} );
112+
}
113+
}
114+
}
115+
pairs.push({
116+
xx:0,
117+
yy:0,
118+
changed:false
119+
}
120+
)
121+
return pairs;
122+
}
123+
124+
export function insertionSort(arr){
125+
const pairs = [];
126+
let n = arr.length;
127+
const prevRect = arr.slice();
128+
for (let i = 1; i < n; ++i) {
129+
let key = prevRect[i].width;
130+
let j = i - 1;
131+
132+
while (j >= 0 && prevRect[j].width > key) {
133+
const recti = {...prevRect[j]};
134+
const rectj = {...prevRect[j+1]};
135+
prevRect[j+1] = recti;
136+
prevRect[j] = rectj;
137+
pairs.push( {
138+
xx:j,
139+
yy:j+1,
140+
changed:true
141+
} );
142+
j = j - 1;
143+
}
144+
// arr[j + 1] = arr[i];
145+
}
146+
for(let i=0;i<n;i++){
147+
pairs.push({
148+
xx:i,
149+
yy:i,
150+
changed:true
151+
})
152+
}
153+
return pairs;
154+
}

0 commit comments

Comments
 (0)