Skip to content

Instantly share code, notes, and snippets.

View scriptpapi's full-sized avatar
🎯
Focusing

Nawaf Abdullah scriptpapi

🎯
Focusing
  • Dubai, United Arab Emirates
View GitHub Profile
@scriptpapi
scriptpapi / graph.py
Created May 19, 2018 21:14
a simple python weighted graph data structure implementation
# 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
@scriptpapi
scriptpapi / BFS.py
Created May 19, 2018 22:44
Simple implementation of Breadth-First Search on a binary tree
# 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
@scriptpapi
scriptpapi / BinarySearch.py
Created May 20, 2018 20:58
Simple implementation of Binary Search algorithm in Python
# 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:
@scriptpapi
scriptpapi / bruteMerge.py
Last active May 22, 2018 18:39
Brute implementation attempt of Merge Sort algorithm from the scratch
# 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]
@scriptpapi
scriptpapi / mergeSort.py
Created May 22, 2018 22:26
Simple merge sort implementation
# 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:]
@scriptpapi
scriptpapi / bubbleSort.py
Created May 22, 2018 22:49
simple bubble sort algorithm implementation
# 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]
@scriptpapi
scriptpapi / quicksort.py
Last active May 23, 2018 17:23 — forked from bcambel/quicksort.py
Simple quick sort implementation
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]]
@scriptpapi
scriptpapi / bitwiseOps.c
Created May 23, 2018 21:29
basic bitwise operations
// 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");
@scriptpapi
scriptpapi / bitwiseOps2.cpp
Created May 23, 2018 22:34
more bitwise manipulations
// 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();
@scriptpapi
scriptpapi / singletonPattern.cpp
Created May 24, 2018 21:29
Singleton design pattern template
// 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(){