forked from bgoonz/DS-ALGO-OFFICIAL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoc.js
More file actions
100 lines (90 loc) · 2.96 KB
/
Copy pathtoc.js
File metadata and controls
100 lines (90 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
let canvas = document.getElementById("canvas"),
ctx = canvas.getContext("2d"),
canvasWidth = window.innerWidth - 50,
canvasHeight = window.innerHeight + 200,
numbers = [];
canvas.width = canvasWidth;
canvas.height = canvasHeight;
ctx.fillRect(0, 0, canvas.width, 7);
// Simple random number generator
function random(min, max) {
return Math.random() * (max - min) + min;
}
// Generate random numbers to populate the structures
function randomizer() {
ctx.clearRect(0, 7, canvas.width, canvas.height);
numbers = [];
for (let i = 0; i < 8; i++) {
numbers.push(Math.floor(random(0, 100)));
}
document.getElementById("numbersArea").innerHTML = numbers;
// document.getElementById("numbersArea").innerHTML = '<button>Some text here</button>';
}
function createBinaryTree() {
ctx.clearRect(0, 7, canvas.width, canvas.height);
// ctx.beginPath();
// ctx.arc(100,75,50,0,2*Math.PI);
// ctx.stroke();
ctx.font = "24px Comfortaa";
ctx.fillText("Insert Binary Tree here - " + numbers, 50, 50);
return;
}
function createQueue() {
ctx.clearRect(0, 7, canvas.width, canvas.height);
var startingTopLeft = canvasWidth / 5.5;
var center = [startingTopLeft + 35, 135];
ctx.font = "22px Comfortaa";
ctx.fillText("Index #:", center[0] - 125, center[1] + 75);
for (var i = 0; i < numbers.length; i++) {
ctx.strokeStyle = "#000000";
ctx.lineWidth = 7;
ctx.strokeRect(startingTopLeft, 75, 100, 100);
ctx.font = "28px Comfortaa";
ctx.fillStyle = "white";
ctx.fillText(numbers[i], center[0], center[1]);
ctx.font = "22px Comfortaa";
ctx.fillStyle = "black";
ctx.fillText(i, center[0], center[1] + 75);
startingTopLeft += 100;
center[0] += 100;
}
}
function createStack() {
ctx.clearRect(0, 7, canvas.width, canvas.height);
var startingX = canvasWidth / 2 - 75;
var startingY = 75;
var center = [startingX + 25, startingY + 50];
ctx.font = "22px Comfortaa";
ctx.fillText("Index #:", center[0] - 155, center[1]);
for (var i = 0; i < numbers.length; i++) {
ctx.strokeStyle = "#000000";
ctx.lineWidth = 7;
ctx.strokeRect(startingX, startingY, 75, 75);
ctx.font = "24px Comfortaa";
ctx.fillStyle = "white";
ctx.fillText(numbers[numbers.length - 1 - i], center[0], center[1]);
ctx.font = "20px Comfortaa";
ctx.fillStyle = "black";
ctx.fillText(numbers.length - 1 - i, center[0] - 55, center[1]);
startingY += 75;
center[1] += 74;
}
}
function createLinkedList() {
ctx.clearRect(0, 7, canvas.width, canvas.height);
ctx.font = "24px Comfortaa";
ctx.fillText("Insert Linked List here - " + numbers, 50, 50);
return;
}
function createHeap() {
ctx.clearRect(0, 7, canvas.width, canvas.height);
ctx.font = "24px Comfortaa";
ctx.fillText("Insert Heap here - " + numbers, 50, 50);
return;
}
function createDblLinkedList() {
ctx.clearRect(0, 7, canvas.width, canvas.height);
ctx.font = "24px Comfortaa";
ctx.fillText("Insert Doubly Linked List here - " + numbers, 50, 50);
return;
}