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
//Copy-Constructor and assignment operator | |
MyClass::MyClass() : /* Fill in initializer list. */ { | |
/* Default initialization here. */ | |
} | |
//copy constructor | |
MyClass::MyClass(const MyClass& other) { | |
copyOther(other); | |
} |
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
#include<iostream> | |
#include<cstring> | |
//Implentation of String class with rule of three | |
class String | |
{ | |
public: | |
String(const char* args) | |
: data_(new char[std::strlen(args) + 1]), length_(std::strlen(args)) |
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
#include<iostream> | |
#include<vector> | |
#include<algorithm> | |
using namespace std; | |
class X { | |
public : | |
void op() { | |
cout << "X::op() " << endl; | |
} |
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
class Queue<T> { | |
/* In Queue updates made at the both ends | |
*/ | |
class Node { | |
T data; | |
Node prev; | |
Node next; | |
Node (T data) { | |
this.data = data; |
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
class HashTable { | |
class Entry { | |
//private final String key; Deleting the Entry ? | |
private String key; | |
private String value; | |
private Entry next; | |
Entry (String key,String value) { | |
this.key = key; | |
this.value = value; |
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 class LRUCache { | |
//Keep track of least recently used elements | |
class Node { | |
String key_; | |
String val_; | |
Node next; | |
Node prev; | |
Node (String key,String val) { | |
this.key_ = key; |
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
List<Integer> list = new LinkedList<Integer>(); | |
//The Good | |
public List<Integer> preorderTraversalRec(TreeNode root) { | |
List<Integer> ans = new ArrayList<Integer>(); | |
if (root == null) { | |
return ans; | |
} | |
ans.add(root.val); | |
ans.addAll(preorderTraversalRec(root.left)); |
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
//T(n) = O(n) | |
int dfsHeight (TreeNode *root) { | |
if (root == NULL) return 0; | |
int leftHeight = dfsHeight (root -> left); | |
if (leftHeight == -1) return -1; | |
int rightHeight = dfsHeight (root -> right); | |
if (rightHeight == -1) return -1; | |
if (abs(leftHeight - rightHeight) > 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
//T(n) = O(n^2) | |
int maxDepth(TreeNode *root) { | |
if (root == NULL) { | |
return 0; | |
} | |
int leftDepth = 0; | |
int rightDepth = 0; | |
leftDepth = maxDepth(root->left); | |
rightDepth = maxDepth(root->right); | |
return 1 + max(leftDepth, rightDepth); |
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
//Augmenting the JS objects (NOTE : in JS function are objects) | |
//Ugly | |
function makePerson(first, last) { | |
return { | |
first: first, | |
last: last | |
}; | |
} | |
function personFullName(person) { |
NewerOlder