Skip to content

Instantly share code, notes, and snippets.

@chasefloyd
chasefloyd / BSTDictionary.java
Last active December 8, 2017 02:57
Project 3
//THIS CLASS USES A BINARY SEARCH TREE TO IMPLEMENT A DICTIONARY
//THIS CLASS MUST IMPLEMENT THE FOLLOWING METHODS
//ADD(K KEY, V VALUE) - INSERTS THE SPECIFIED KEY-VALUE PAIR INTO THE DICTIONARY, SHOULD REPLACE THE KEYS VALUE IT KEY ALREADY EXISTS
//GETVALUE(K KEY) - RETURNS THE VALUE ASSOCIATED WITH THE SPECIFIED KEY
//CONTAINS(K KEY) - RETURNS WHETHER THE SPECIFIED KEY EXISTS IN THE DICTIONARY
//ITERATOR() - RETURNS AN ITERATOR OVER THE ELEMENTS IN THE DICTIONARY
// i am not sure if my iterator method is correctly coded
// also i am not sure about the entry class in this. In the genKey class i am trying to use the enhanced for loop to read through the ntries
import java.util.Stack;
import java.util.Scanner;
public class Infix {
public static int evaluate(String expression) {
//char[] nextItem = expression.toCharArray();
String[] nextItem = expression.split(" ");
Stack<Integer> operands = new Stack<>();
Stack<String> operators = new Stack<>();
@chasefloyd
chasefloyd / Inverse
Created November 1, 2017 18:32
Python solution for inversing lists
def inverse(A, B, f):
x = []
for i in range(len(f)):
x.append(f[i][::-1])
return x
A = [1, 2, 3]
B = [1, 5, 6]
f = [[1, 4], [2, 5], [3, 6]]
@chasefloyd
chasefloyd / isOnto
Created November 1, 2017 18:31
Python solution for determining if a function is onto
def isOnto(A,B,f):
x = []
for i in range(len(f)):
x.append(f[i][1])
#print(x)
i+=1
B = sorted(B)
x = list(set(x))
if B == x:
return True
@chasefloyd
chasefloyd / isOneToOne
Created November 1, 2017 18:30
Python solution for determining if a function is one to one
def isOneToOne(A, B, f):
x = []
i = 0
for i in range(len(f)):
x.append(f[i][1])
i+=1
x = sorted(x)
#print(x)
seen = set()
@chasefloyd
chasefloyd / Image
Created November 1, 2017 18:29
Python solution for returning the range
def image(f):
x = [f[0][1], f[1][1], f[2][1]]
x = sorted(x)
return list(set(x))
f = [[1,4],[2,5],[3,4]]
print(image(f))
@chasefloyd
chasefloyd / isFunction
Created November 1, 2017 18:28
Python solution to determining a function
def isFunction(A, B, f):
x = []
for i in range(len(f)):
x.append(f[i][0])
#print(x)
if len(x) != len(A):
return False
else:
for s in A:
#print(s)
public class ArrayList<E> implements List<E> { // The type parameter E is a placeholder for what kind of data will be stored in this list
private E[] data = (E[])(new Object[3]); // The array where the data is stored -- Java doesn't allow generic array creation, so we just create an array of Objects and cast it to E[]
private int size = 0; // The number of elements actually stored in the list
// Returns the item stored at the specified list index
// Big-O: O(1)
public E get(int index) {
if (index >= 0 && index < size)
return data[index];
else {
@chasefloyd
chasefloyd / Othello
Created October 12, 2017 01:26
The Othello game
/**
* Chase Floyd
*
* This class serves as the main client program for the game
*
* This class should include at least these instance varibales
* a GameBoard object to store the state of the game
* a Scanner object to read user input
*
* This class should contain the main method that is executed to start the game
@chasefloyd
chasefloyd / TuitionProblem
Created October 25, 2016 03:29
Tuition problem
creditHour=int(input("How many total hours are you taking? "))
advancedHour=int(input("How many of those hours are from engineering/science classes? "))
tuition = creditHour * 350
specialTuition = advancedHour * 25
reducedTuition = creditHour * 40
if creditHour >= 0 and creditHour <= 12:
print(tuition + specialTuition)
else: