Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
e3cef89
Created ArrayList class implementing List
theZalmanian Feb 13, 2024
6320b7c
Created test directory and setup test file for ArrayList
theZalmanian Feb 13, 2024
a592f01
Implemented constructor for the ArrayList class
theZalmanian Feb 13, 2024
4eb65c3
Implemented ArrayList's get and set methods
theZalmanian Feb 13, 2024
55463c2
Implemented ArrayList's contains method
theZalmanian Feb 14, 2024
13477ae
Implemented ArrayList's removeFront, removeBack, remove item, and rem…
theZalmanian Feb 14, 2024
11221a8
Added doubleMaxCapacity method to ArrayList
theZalmanian Feb 14, 2024
14ca13c
Added tests for ArrayList's addFront, addBack, and add methods
theZalmanian Feb 14, 2024
a7c11de
Refactored set method of ArrayList
theZalmanian Feb 14, 2024
1163525
Refactored ArrayList checks to utilize isEmpty
theZalmanian Feb 14, 2024
ad16279
Implemented tests for ArrayList's contains method
theZalmanian Feb 14, 2024
e725a98
Implemented tests for ArrayList's removeFront and removeBack methods
theZalmanian Feb 14, 2024
56048d4
Implemented tests for ArrayList's remove(index) method
theZalmanian Feb 14, 2024
c6df241
Refactored remove(item) method of ArrayList
theZalmanian Feb 14, 2024
6c09b60
Implemented iterator for ArrayList
theZalmanian Feb 14, 2024
e506d92
Set up LinkedList class and test files
theZalmanian Feb 14, 2024
f91aae7
Implemented LinkedList's size, isEmpty, and contains methods
theZalmanian Feb 15, 2024
76f49d9
Added constructor to LinkedList and its Node
theZalmanian Feb 15, 2024
2515cbc
Implemented addBack and get methods for LinkedList
theZalmanian Feb 15, 2024
288a537
Implemented tests for addFront and addBack
theZalmanian Feb 15, 2024
dd34dbd
Committed wrong file last time
theZalmanian Feb 15, 2024
dad9e26
Implemented LinkedList's removeFront and removeBack methods
theZalmanian Feb 15, 2024
cf36daf
Implemented LinkedList's add method and tests for it
theZalmanian Feb 15, 2024
42e0cbe
Implemented LinkedList's set method and tests for it
theZalmanian Feb 15, 2024
f367ee9
Implemented an iterator helper for LinkedList
theZalmanian Feb 15, 2024
743e689
Implemented and tested LinkedList's remove(index) method
theZalmanian Feb 15, 2024
e60d559
Implemented and tested LinkedList's remove(item) method
theZalmanian Feb 15, 2024
ccd5edc
Organized project, created Bag interface file
theZalmanian Feb 15, 2024
c2c9f81
Created Bag interface
theZalmanian Feb 15, 2024
8cce402
Created ResizingArrayStack implementing Stack
theZalmanian Feb 15, 2024
373ffd3
Added helper fields to ResizingArrayStack
theZalmanian Feb 15, 2024
266ed4f
Implemented ResizingArrayStack's push method
theZalmanian Feb 15, 2024
76d20c5
Implemented ResizingArrayStack's pop method
theZalmanian Feb 15, 2024
856b525
Implemented ResizingArrayStack's peek method
theZalmanian Feb 15, 2024
07feb50
Fixed file migration documentation wonkyness
theZalmanian Feb 15, 2024
3e13500
Implemented iterator for ResizingArrayStack
theZalmanian Feb 15, 2024
02e58a4
Fixed and finalized ResizingArrayStack and tester
theZalmanian Feb 15, 2024
dbeb94f
Created LinkedStack implementing Stack
theZalmanian Feb 15, 2024
d1852d8
Implemented LinkedStack's push, pop, and peek methods
theZalmanian Feb 15, 2024
74b841c
Implemented iterator for LinkedStack
theZalmanian Feb 15, 2024
e01bac7
Placed all stack related files in package
theZalmanian Feb 15, 2024
e5579aa
Created LinkedQueue implementing Queue
theZalmanian Feb 15, 2024
f660037
Implemented LinkedQueue's enqueue, dequeue, isEmpty, and size methods
theZalmanian Feb 15, 2024
8927d5a
Implemented iterator for LinkedQueue
theZalmanian Feb 15, 2024
09affd6
Setup tester for LinkedQueue
theZalmanian Feb 18, 2024
8be52e0
Created LinkedBag implementing Bag and added helpers and constructor
theZalmanian Feb 18, 2024
3c8237e
Implemented all methods + iterator for LinkedBag implementation
theZalmanian Feb 18, 2024
6e60107
Implemented tester for LinkedBag
theZalmanian Feb 18, 2024
d0a581f
Conducted runtime analysis of ArrayList and LinkedList implementations
theZalmanian Feb 18, 2024
dd770c2
Conducted runtime analysis of ResizingArrayStack and LinkedStack
theZalmanian Feb 18, 2024
d7ce59e
Organized project layout by grouping interfaces w/ their implementati…
theZalmanian Feb 18, 2024
2e7771a
Conducted a runtime analysis of LinkedQueue and LinkedBag
theZalmanian Feb 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions SDEV333-Term-Project.iml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library name="JUnit5.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
26 changes: 26 additions & 0 deletions src/Bag/Bag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package Bag;

/**
* An implementation of the Bag data structure
* @param <E> Class may store various types of values
* @author Zalman I.
*/
public interface Bag<E> extends Iterable<E> {
/**
* Adds the given item to the bag
* @param item the item to be added
*/
void add(E item);

/**
* Checks whether the bag is empty, and returns true/false accordingly
* @return true if the bag is empty; otherwise false
*/
boolean isEmpty();

/**
* Gets and returns the number of items stored in the bag
* @return the number of items stored in the bag
*/
int size();
}
169 changes: 169 additions & 0 deletions src/Bag/LinkedBag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package Bag;

import java.util.Iterator;
import java.util.NoSuchElementException;

/**
* Implementation of a Bag using a "list" of nodes and a Bag interface for generics
* @param <E> Class may store various types of values
* @author Zalman I.
*/
public class LinkedBag<E> implements Bag<E> {
/**
* A container which contains an item and a connection to another Node
*/
private class Node {
/**
* The item stored within the Node
*/
E item;

/**
* The node this Node is pointing to
*/
Node next;

/**
* Creates a node, and stores the given item within it
*
* Runtime: O(1) as it always takes the same runtime to conduct this operation
*
* @param item the item being stored in node
*/
public Node(E item) {
// store given item
this.item = item;

// node starts off disconnected
next = null;
}
}

/**
* The first node in bag
*/
private Node first;

/**
* The number of items stored in this bag
*/
private int size;

/**
* Constructs an empty LinkedBag
*
* Runtime: O(1) as it always takes the same runtime to conduct this operation
*/
public LinkedBag() {
// bag starts off empty
first = null;
size = 0;
}

/**
* Adds the given item to the bag
*
* Runtime: O(1) as we can instantly add a new item to start of list via the first variable,
* regardless of how many nodes exist in bag.
*
* @param item the item to be added
*/
@Override
public void add(E item) {
// create new node containing given item
Node newNode = new Node(item);

// if the bag is not empty
if(!isEmpty()) {
// point new node at first, so it isn't lost
newNode.next = first;
}

// override first with newly created node
// (making new node first node in bag)
first = newNode;

// account for new item in bag
size++;
}

/**
* Checks whether the bag is empty, and returns true/false accordingly
*
* Runtime: O(1) as we are instantly accessing variables and checking a condition.
* This operation would always take the same runtime to conduct.
*
* @return true if the bag is empty; otherwise false
*/
@Override
public boolean isEmpty() {
return size == 0 && first == null;
}

/**
* Gets and returns the number of items stored in the bag
*
* Runtime: O(1) as we are instantly retrieving a variable.
* This operation would always take the same runtime to conduct.
*
* @return the number of items stored in the bag
*/
@Override
public int size() {
return size;
}

/**
* Returns an iterator over elements of type {@code T}.
*
* @return an Iterator.
*/
@Override
public Iterator<E> iterator() {
return new LinkedBagIterator();
}

/**
* Implementation of an Iterator for the LinkedBag class
*/
private class LinkedBagIterator implements Iterator<E>
{
/**
* The current Node being tracked by the Iterator
*/
private Node current;

/**
* Constructs a LinkedBag iterator, with the first node tracked first
*/
LinkedBagIterator() {
current = first;
}

/**
* Checks if list contains another element, and returns true/false accordingly
* @return true if list contains another element; otherwise false
*/
public boolean hasNext() {
return current != null;
}

/**
* Gets and returns the first item in the list
* @return the first item in the list
*/
public E next() {
if(!hasNext()) {
throw new NoSuchElementException();
}

// get first item of list
E currItem = current.item;

// move on to the next item
current = current.next;

return currItem;
}
}
}
44 changes: 44 additions & 0 deletions src/Bag/Stats.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package Bag;

import java.util.Scanner;

public class Stats
{
public static void main(String[] args) {
// setup storage bag
Bag<Double> numbers = new LinkedBag<Double>();

// setup scanner, taking in given string
Scanner line = new Scanner("100 99 101 120 98 107 109 81 101 90");

// run through line
while (line.hasNextDouble()) {
// get current item and add to bag
numbers.add(line.nextDouble());
}

// track number of items in bag
int size = numbers.size();

// run through bag and add up all items
double sum = 0.0;
for (double currNum : numbers) {
sum += currNum;
}

// get the mean of all numbers in bag
double mean = sum / size;

// clear total tracker and use again to calculate standard dev
sum = 0.0;
for (double currNum : numbers) {
sum += (currNum - mean) * (currNum - mean);
}

double std = Math.sqrt(sum / (size - 1));

// display calculation results
System.out.printf("Mean: %.2f\n", mean);
System.out.printf("Std dev: %.2f\n", std);
}
}
2 changes: 2 additions & 0 deletions src/Deque.java → src/Examples/Deque.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package Examples;

/**
* Deque: double-ended queue API
* Supports adding and removing items at both ends.
Expand Down
2 changes: 2 additions & 0 deletions src/MathSet.java → src/Examples/MathSet.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package Examples;

/**
* MathSet API (interface / abstract data type)
* represents a mathematical set. Sets in mathematics
Expand Down
Loading