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
# Simple graph implementation (not tested) | |
class Node: | |
def __init__(self, newData): | |
self.data = newData | |
self.adjacencyList = {} | |
def addAdjacent(self, adj, weight): | |
self.adjacencyList[adj] = weight |
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
# Simple implementation of Breadth-First Search on a binary tree | |
from collections import deque | |
class Node: | |
def __init__(self, newData): | |
self.data = newData | |
self.left = None | |
self.right = None |
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
# Simple implementation of Binary Search algorithm | |
# Sorting included | |
from math import ceil | |
def Bsearch(item, list): | |
s_index = int(ceil(len(list)/2)) | |
list.sort() | |
found = False | |
while 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
# Brute implementation attempt of Merge Sort algorithm from the scratch | |
from math import ceil | |
import random | |
def divide(ListofLists): | |
newList = list() | |
for i in range(len(ListofLists)): | |
if len(ListofLists[i]) > 2: | |
tmp = ListofLists[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
# Simple merge sort implementation | |
# reference: http://interactivepython.org/courselib/static/pythonds/SortSearch/TheMergeSort.html | |
import random | |
def mergeSort(iList): | |
if len(iList) > 1: | |
mid = len(iList) // 2 | |
lList = iList[:mid] | |
rList = iList[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
# simple bubble sort implementation | |
import random | |
def bubbleSort(iList): | |
for i in range(len(iList)): | |
try: | |
if iList[i] > iList[i+1]: | |
tmp = iList[i] | |
iList[i] = iList[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
import random | |
def quickSort(iList): | |
print("ALL", iList) | |
if len(iList) <= 1: | |
return iList | |
else: | |
left = quickSort([x for x in iList[1:] if x<iList[0]]) | |
middle = [iList[0]] |
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
// some bitwise operations | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main() { | |
unsigned char a = 5; | |
unsigned char b = 9; | |
printf("a= %d, b= %d\n", a, b); | |
printf("binary a= 00000101, b= 00001001\n"); |
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
// more bitwise manipulations | |
#include <iostream> | |
using namespace std; | |
void set(int &num, int pos); | |
void toggle(int &num, int pos); | |
void unset(int &num, int pos); | |
void cudi(); |
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
// A Template for implementing singleton design pattern. | |
class Singleton | |
{ | |
public: | |
int getX(){ return var_x;} | |
int getY(){ return var_y;} | |
void setX(int x){ var_x = x;} | |
void setY(int y){ var_y = y;} | |
static Singleton *instance(){ |