Skip to content

Instantly share code, notes, and snippets.

View dineshrajpurohit's full-sized avatar

Dinesh Purohit dineshrajpurohit

View GitHub Profile
@dineshrajpurohit
dineshrajpurohit / exercise-fibonacci-closure.go
Created January 30, 2017 09:33
Fibonacci using closure in Go - Excercise
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
x := 0
y := 1
return func() int{
/**
* Dinesh
*
*/
//package com.dinesh.tutorials;
public static void pascal(int n){
int[][] pas = new int[n][];
for(int i=0; i<n;i++){
pas[i] = new int[i+1];
// Sieve of erosthenes
public static void primes(int n){
Boolean[] prime = new Boolean[n+1];
for(int i=2;i<=n;i++){
prime[i] = true;
}
for(int div=2;div*div<=n;div++){
if(prime[div] == true){
public Boolean isValidBinary(BinaryTreeNode root, BinaryTreeNode prev){
// Stack 3 2 1
// 1 2 3
// if(current.left != null ){
// Boolean left = isValidBinary(current.left);
// if(left == false)
// return false;
// else{
@dineshrajpurohit
dineshrajpurohit / NumberAndRomanMain.java
Last active August 29, 2015 14:05
Number to Roman Conversion and Roman to Number conversion
package com.dinesh.tutorials;
class NumberAndRoman{
/**
* Converting the Numbers to Roman Numbers
*
**/
public static String convertToRoman(int num){
String rom = "";
@dineshrajpurohit
dineshrajpurohit / RootedTreeTraversal.js
Last active September 27, 2018 05:38
Preorder, Postorder,Inorder and Levelorder traversal of rooted trees using Javascript
/**
*
* Dinesh
*
* RootedTreeTraversal
* - Preorder Traversal
* - Postorder Traversal
* - Inorder Traversal
* - Levelorder Traversal
*
@dineshrajpurohit
dineshrajpurohit / RootedTreeTraversals.java
Last active October 29, 2018 15:35
Preorder, Postorder,Inorder and Levelorder traversal of rooted trees using Java
/**
*
* Dinesh
*
* RootedTreeTraversal
* - Preorder Traversal
* - Postorder Traversal
* - Inorder Traversal
* - Levelorder Traversal
*
@dineshrajpurohit
dineshrajpurohit / InfixToPostfix.js
Created August 16, 2014 06:45
Infix to Postfix conversion using Javascript
/**
* Infix to postfix implementation
*
* Dinesh
*
* Input: 4+8*6-5/3-2*2+2 ==> 486*+53/-22*-2+
*
* Algorithm:
* - Whenever an integer/character comes from expression we append to postfix String
* - Whenever a operator comes in we check the precedence of the incoming operator with the
@dineshrajpurohit
dineshrajpurohit / PostFix.js
Last active August 29, 2015 14:05
Executing Postfix expression implementation using Javascript
/**
*
* Postfix implementation using StackList:
* Code for stacklist: https://gist.github.com/dineshrajpurohit/0bb67d29a039f85f2f10
*
* Dinesh
*
* PostFix Expression parsing and getting the result
*
* e.g: 42+351-*+ ==> 18
@dineshrajpurohit
dineshrajpurohit / StackList.js
Last active August 29, 2015 14:05
Stack implementation using Linked list in Javascript
/**
* Implementation of Stacks using Linked List
*
* Dinesh
*
*/
// Namespace
var EX = {};