Skip to content

Instantly share code, notes, and snippets.

View sumedhe's full-sized avatar
馃槆
Feeling Fantastic...

Sumedhe Dissanayake sumedhe

馃槆
Feeling Fantastic...
View GitHub Profile
class Queue:
def __init__(self):
self.items = []
def enqueue(self, item):
self.items.append(item)
def dequeue(self):
return self.items.pop(0)
from queue import *
class Node:
def __init__(self, val):
self.data = val
self.left = None
self.right = None
def insert(self, val):
if val < self.data:
class Node:
def __init__(self, val):
self.data = val
self.next = None
self.prev = None
class LinkedList:
def __init__(self):
self.head = None
self.tail = None
@sumedhe
sumedhe / sortingBasic.py
Last active July 9, 2016 11:03
buble sort, selection sort and insertion sort
## Basic Sorting Algorithms
def bubleSort(lst):
n = len(lst)
for i in range(n-1):
for j in range(n-1-i):
if lst[j]>lst[j+1]:
tmp = lst[j+1]
lst[j+1] = lst[j]
lst[j] = tmp
class Stack:
def __init__(self):
self.items = []
def push(self, item):
self.items.append(item)
def pop(self):
return self.items.pop()
@sumedhe
sumedhe / reverseString.py
Created July 9, 2016 10:59
reverse a string using stack
class Stack:
def __init__(self):
self.items = []
def push(self, item):
self.items.append(item)
def pop(self):
return self.items.pop()
@sumedhe
sumedhe / palindromeCheck.py
Last active July 9, 2016 11:02
check whether a string is palindrome or not
class Stack:
def __init__(self):
self.items = []
def push(self, item):
self.items.append(item)
def pop(self):
return self.items.pop()
@sumedhe
sumedhe / graph.py
Created November 15, 2016 18:38
Directed Graph using Dictionary
class Graph:
def __init__(self):
self.dic = {}
def addVertex(self, vert):
if vert not in self.dic:
self.dic[vert] = []
def addEdge(self, start, end):
if end not in self.dic[start]:
@sumedhe
sumedhe / undirectedGraph.py
Created November 15, 2016 18:39
Undirected Graph using Dictionary
class Graph:
def __init__(self):
self.dic = {}
def addVertex(self, vert):
if vert not in self.dic:
self.dic[vert] = []
def addEdge(self, start, end):
if end not in self.dic[start]:
class Vertex:
def __init__(self, value):
self.value = value
self.adjacents = []
self.state = 0
class Graph:
def __init__(self):
self.vertices = []
# self.edges = []