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
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{ |
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
/** | |
* 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]; |
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
// 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){ |
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
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{ |
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
package com.dinesh.tutorials; | |
class NumberAndRoman{ | |
/** | |
* Converting the Numbers to Roman Numbers | |
* | |
**/ | |
public static String convertToRoman(int num){ | |
String rom = ""; |
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
/** | |
* | |
* Dinesh | |
* | |
* RootedTreeTraversal | |
* - Preorder Traversal | |
* - Postorder Traversal | |
* - Inorder Traversal | |
* - Levelorder Traversal | |
* |
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
/** | |
* | |
* Dinesh | |
* | |
* RootedTreeTraversal | |
* - Preorder Traversal | |
* - Postorder Traversal | |
* - Inorder Traversal | |
* - Levelorder Traversal | |
* |
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
/** | |
* 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 |
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
/** | |
* | |
* 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 |
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
/** | |
* Implementation of Stacks using Linked List | |
* | |
* Dinesh | |
* | |
*/ | |
// Namespace | |
var EX = {}; |
NewerOlder