This file contains 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
function balancedParentheses (string) { | |
var stack = new Stack(); | |
var i, len; | |
string = string | |
// remove any strings or regexes used in target string (if it is a function for example) | |
.replace(/(\`.{0,}\`|\/.{0,}\/|\'.{0,}\'|\".{0,}\")/g, ''); | |
for (i = 0, len = string.length; i < len; i++) { | |
switch (string[i]) { |
This file contains 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
function evalPostfix (expr) { | |
var i = 0, len = 0, op1, op2; | |
var stack = new Stack(); | |
for (i = 0, len = expr.length; i < len; i++) { | |
if (expr[i].match(/[^\+\-\*\/\%]/)) { | |
stack.push(expr[i]); | |
} else { | |
op2 = stack.pop(); | |
op1 = stack.pop(); |
This file contains 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
function infixToPostfixNoParentheses (expr) { | |
var postfix = '', i = 0, len = 0; | |
var stack = new Stack(); | |
for (i, len = expr.length; i < len; i++) { | |
if (expr[i].match(/[^\+\-\*\/\%]/)) { | |
postfix += expr[i]; | |
} else if (stack.isEmpty()) { | |
stack.push(expr[i]); | |
} else { |
This file contains 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
function infixToPostfixWithParentheses (expr) { | |
if (!balancedParentheses(expr)) return false; | |
var postfix = '', i = 0, len = 0; | |
var stack = new Stack(); | |
for (i, len = expr.length; i < len; i++) { | |
if (expr[i].match(/[^\(\)\+\-\*\/\%]/)) { | |
postfix += expr[i]; | |
} else if (stack.isEmpty()) { |
This file contains 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
function Stack () { | |
this.__arr = []; | |
} | |
Stack.prototype = { | |
constructor : Stack, | |
push : function push (elem) { | |
if (typeof elem !== 'undefined') return this.__arr.push(elem); | |
}, | |
pop : function pop () { |
This file contains 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
function StaticQueue (size) { | |
this.__arr = {}; | |
this.__size = size; | |
this.__front = -1; | |
this.__rear = -1; | |
for (var i = 0; i < size; i++) { | |
this.__arr[i] = undefined; | |
} | |
} |
This file contains 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
function Node (val) { | |
this.val = val; | |
this.next = null; | |
} | |
function LinkedList (firstVal) { | |
this.__head = null; | |
this.__length = 0; | |
if (typeof firstVal !== 'undefined') { | |
this.append(firstVal); |
This file contains 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
// first = true - find first occurance | |
// first = false - find last occurance | |
// first = undefined - first found | |
function binarySearch(array, x, first) { | |
var start = 0, end = array.length - 1, mid = 0, result = -1; | |
while (start <= end) { | |
mid = Math.floor((start + end) / 2); | |
if (array[mid] == x) { | |
result = mid; |
This file contains 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
function BinarySearchTree (rootData) { | |
this.root = null; | |
this.nodes = 0; | |
this.add(rootData); | |
} | |
BinarySearchTree.prototype = { | |
constructor : BinarySearchTree, | |
add : function add (data) { | |
if (this.root === null) { |
This file contains 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
import React from 'react'; | |
import { Motion, spring, presets } from 'react-motion'; | |
import Swipeable from './Swipeable'; | |
import styled from 'styled-components' | |
const ReseteUl = styled.ul` | |
margin: 0; | |
padding: 0; |
OlderNewer