Skip to content

Instantly share code, notes, and snippets.

@cxrayana
cxrayana / HW8-P2.py
Created July 26, 2023 04:56
CS582-R342D927-HW8
class Graph:
def __init__(self):
self.adj_list = {}
def add_edge(self, u, v):
if u not in self.adj_list:
self.adj_list[u] = []
self.adj_list[u].append(v)
def dfs(self, start, visited=None):
@cxrayana
cxrayana / HW8-P1.py
Created July 26, 2023 04:55
CS582-R342D927
from collections import deque
class Graph:
def __init__(self):
self.adj_list = {}
def add_edge(self, u, v):
if u not in self.adj_list:
self.adj_list[u] = []
self.adj_list[u].append(v)
@cxrayana
cxrayana / HW7-P2.py
Created July 26, 2023 04:52
CS582-R342D927
class TreeNode:
def __init__(self, key, left=None, right=None):
self.key = key
self.left = left
self.right = right
class LinkedBST:
def __init__(self):
self.root = None
self.size = 0
@cxrayana
cxrayana / HW7-P1.py
Created July 26, 2023 04:49
CS582-R342D927
import math
class TreeNode:
def __init__(self, key, left=None, right=None):
self.key = key
self.left = left
self.right = right
class LinkedBST:
def __init__(self):
@cxrayana
cxrayana / HW6-P2.py
Created July 19, 2023 04:13
CS582-R342D927-HW6
class AbstractCollection(object):
"""An abstract collection implementation."""
# Constructor
def __init__(self, sourceCollection = None):
"""Sets the initial state of self, which includes the
contents of sourceCollection, if it's present."""
self.size = 0
if sourceCollection:
@cxrayana
cxrayana / HW6-P1.py
Created July 19, 2023 04:02
CS582-R342D927
class Array(object):
"""Represents an array."""
def __init__(self, capacity, fillValue = None):
"""Capacity is the static size of the array.
fillValue is placed at each position."""
self.items = list()
for count in range(capacity):
self.items.append(fillValue)
@cxrayana
cxrayana / HW4-P7.py
Created July 14, 2023 03:24
CS582-R342D927-RaggedGrid
class Array(object):
"""Represents an array."""
def __init__(self, capacity, fillValue=None):
"""Capacity is the static size of the array.
fillValue is placed at each position."""
self._items = [fillValue] * capacity
def __len__(self):
"""-> The capacity of the array."""
@cxrayana
cxrayana / HW4-P7.py
Created July 14, 2023 03:16
CS582-R342D927
class Array(object):
"""Represents an array."""
def __init__(self, capacity, fillValue=None):
"""Capacity is the static size of the array.
fillValue is placed at each position."""
self._items = [fillValue] * capacity
def __len__(self):
"""-> The capacity of the array."""
@cxrayana
cxrayana / HW4-P6.py
Created July 14, 2023 02:56
CS582-R342D927-Operations on arrays
class Array(object):
"""Represents an array."""
def __init__(self, capacity, fillValue=None):
"""Capacity is the static size of the array.
fillValue is placed at each position."""
self._items = [fillValue] * capacity
def __len__(self):
"""-> The capacity of the array."""
@cxrayana
cxrayana / HW4-P5.py
Last active July 14, 2023 03:13
CS582-R342D927
class Array(object):
"""Represents an array."""
def __init__(self, capacity, fillValue=None):
"""Capacity is the static size of the array.
fillValue is placed at each position."""
self._items = [fillValue] * capacity
def __len__(self):
"""-> The capacity of the array."""