Created
June 9, 2023 20:48
-
-
Save cod3smith/f457f34344b7e807e357c88fe0b9823e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Node: | |
def __init__(self, value): | |
self.value = value | |
self.next = None | |
self.down = None | |
class DecisionMatrix: | |
def __init__(self, rows, columns): | |
self.rows = rows | |
self.columns = columns | |
self.head = self.build_matrix() | |
def build_matrix(self): | |
# Create the matrix | |
head = Node(None) | |
current = head | |
# Create rows | |
for _ in range(self.rows - 1): | |
current.down = Node(None) | |
current = current.down | |
# Create columns | |
current_row = head | |
for _ in range(self.rows): | |
current_column = current_row | |
for _ in range(self.columns - 1): | |
current_column.next = Node(None) | |
current_column = current_column.next | |
current_row = current_row.down | |
return head | |
def get_value(self, row, column): | |
# Find the node at the specified row and column | |
current_row = self.head | |
for _ in range(row): | |
current_row = current_row.down | |
current_column = current_row | |
for _ in range(column): | |
current_column = current_column.next | |
return current_column.value | |
def set_value(self, row, column, value): | |
# Find the node at the specified row and column | |
current_row = self.head | |
for _ in range(row): | |
current_row = current_row.down | |
current_column = current_row | |
for _ in range(column): | |
current_column = current_column.next | |
current_column.value = value | |
# Example usage | |
matrix = DecisionMatrix(3, 4) | |
matrix.set_value(0, 0, 'Yes') | |
matrix.set_value(1, 2, 'No') | |
matrix.set_value(2, 3, 'Maybe') | |
print(matrix.get_value(0, 0)) # Output: Yes | |
print(matrix.get_value(1, 2)) # Output: No | |
print(matrix.get_value(2, 3)) # Output: Maybe | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment