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 / 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 / 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 / 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 / hashTable.py
Last active May 19, 2018 21:15
A simple hash table implementation
# A simple of implementation of a hash table
class Node:
def __init__(self, key, newData):
self.key = key
self.data = newData
def getKey(self):
return self.key
@scriptpapi
scriptpapi / vector.cpp
Last active May 19, 2018 21:16
a simple C++ vector implementation with some applications
//A Simple implementation of vector(containing objects of a class) data structure
#include <iostream>
#include <vector>
using namespace std;
class Salad{
private:
int oranges, apples;
public:
void setOranges(int numOranges){ oranges = numOranges; }
@scriptpapi
scriptpapi / trie.py
Last active May 20, 2018 03:51 — forked from zshihang/trie.py
A simple Python Trie data structure implementation
# A simple Trie implementation
class Node:
def __init__(self):
self.children = dict()
self.count = 0
class Trie:
@scriptpapi
scriptpapi / BTree.py
Last active May 20, 2018 19:48
A simple complete binary tree implementation
# A simple complete binary tree implementation with DFS methods
class Node:
def __init__(self, newData):
self.data = newData
self.left = None
self.right = None
def getData(self):
@scriptpapi
scriptpapi / DoublyLinkedList.py
Created May 14, 2018 06:06
Basic implementation of doubly linked list
# Basic implementation of doubly linked list
class Node:
def __init__(self, data):
self.data = data
self.next = None
self.prev = None
def getData(self):
return self.data
@scriptpapi
scriptpapi / SinglyLinkedList.py
Last active May 13, 2018 23:16
Basic implementation of singly linked list
# Basic implementation of singly linked list
class Node:
def __init__(self, data):
self.data = data
self.next = None
def getData(self):
return self.data
def setData(self, newData):
# Basic queue implementation: using collections
from collections import deque
class Queue:
def __init__(self):
self.items = deque()
def isEmpty(self):
return self.items == deque([])