first commit
This commit is contained in:
16
Labs/Lab 6/.idea/checkstyle-idea.xml
generated
Normal file
16
Labs/Lab 6/.idea/checkstyle-idea.xml
generated
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CheckStyle-IDEA">
|
||||
<option name="configuration">
|
||||
<map>
|
||||
<entry key="checkstyle-version" value="8.5" />
|
||||
<entry key="copy-libs" value="true" />
|
||||
<entry key="location-0" value="BUNDLED:(bundled):Sun Checks" />
|
||||
<entry key="location-1" value="BUNDLED:(bundled):Google Checks" />
|
||||
<entry key="scan-before-checkin" value="false" />
|
||||
<entry key="scanscope" value="JavaOnly" />
|
||||
<entry key="suppress-errors" value="false" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
6
Labs/Lab 6/.idea/misc.xml
generated
Normal file
6
Labs/Lab 6/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
Labs/Lab 6/.idea/modules.xml
generated
Normal file
8
Labs/Lab 6/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Lab 6.iml" filepath="$PROJECT_DIR$/Lab 6.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
286
Labs/Lab 6/.idea/workspace.xml
generated
Normal file
286
Labs/Lab 6/.idea/workspace.xml
generated
Normal file
@@ -0,0 +1,286 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="21e926f9-529f-43a8-8440-6c9783336547" name="Default" comment="" />
|
||||
<ignored path="$PROJECT_DIR$/out/" />
|
||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="CheckStyle-IDEA-workspace">
|
||||
<option name="configuration">
|
||||
<map>
|
||||
<entry key="last-active-plugin-version" value="5.22.1" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="FileEditorManager">
|
||||
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
|
||||
<file pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/src/barnestr/Tester.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="1285">
|
||||
<caret line="218" selection-start-line="218" selection-end-line="218" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/src/barnestr/ArrayList.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="1598">
|
||||
<caret line="110" selection-start-line="110" selection-end-line="110" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/src/barnestr/LinkedList.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="2057">
|
||||
<caret line="132" column="13" selection-start-line="132" selection-start-column="13" selection-end-line="132" selection-end-column="13" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
</leaf>
|
||||
</component>
|
||||
<component name="IdeDocumentHistory">
|
||||
<option name="CHANGED_PATHS">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/src/barnestr/LinkedList.java" />
|
||||
<option value="$PROJECT_DIR$/src/barnestr/Tester.java" />
|
||||
<option value="$PROJECT_DIR$/src/barnestr/ArrayList.java" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectFrameBounds">
|
||||
<option name="x" value="-7" />
|
||||
<option name="width" value="1294" />
|
||||
<option name="height" value="1092" />
|
||||
</component>
|
||||
<component name="ProjectView">
|
||||
<navigator proportions="" version="1">
|
||||
<foldersAlwaysOnTop value="true" />
|
||||
</navigator>
|
||||
<panes>
|
||||
<pane id="ProjectPane" />
|
||||
<pane id="Scope" />
|
||||
<pane id="PackagesPane" />
|
||||
</panes>
|
||||
</component>
|
||||
<component name="PropertiesComponent">
|
||||
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||
<property name="aspect.path.notification.shown" value="true" />
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$/../../../../2017-2018/SE 1021/Spring 2018/Lab 7" />
|
||||
<property name="project.structure.last.edited" value="Project" />
|
||||
<property name="project.structure.proportion" value="0.0" />
|
||||
<property name="project.structure.side.proportion" value="0.2" />
|
||||
<property name="settings.editor.selected.configurable" value="preferences.lookFeel" />
|
||||
</component>
|
||||
<component name="RunDashboard">
|
||||
<option name="ruleStates">
|
||||
<list>
|
||||
<RuleState>
|
||||
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
|
||||
</RuleState>
|
||||
<RuleState>
|
||||
<option name="name" value="StatusDashboardGroupingRule" />
|
||||
</RuleState>
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="RunManager">
|
||||
<configuration default="true" type="Applet">
|
||||
<option name="HEIGHT" value="0" />
|
||||
<option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" />
|
||||
<option name="WIDTH" value="0" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="Tester" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="barnestr.Tester" />
|
||||
<module name="Lab 6" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="barnestr.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration default="true" type="Application" factoryName="Application">
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration default="true" type="JUnit" factoryName="JUnit">
|
||||
<option name="TEST_OBJECT" value="class" />
|
||||
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration default="true" type="TestNG">
|
||||
<option name="TEST_OBJECT" value="CLASS" />
|
||||
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
|
||||
<properties />
|
||||
<listeners />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration default="true" type="#org.jetbrains.idea.devkit.run.PluginConfigurationType">
|
||||
<module name="" />
|
||||
<option name="VM_PARAMETERS" value="-Xmx512m -Xms256m -XX:MaxPermSize=250m -ea" />
|
||||
<option name="PROGRAM_PARAMETERS" />
|
||||
<predefined_log_file enabled="true" id="idea.log" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
||||
<component name="SvnConfiguration">
|
||||
<configuration />
|
||||
</component>
|
||||
<component name="TaskManager">
|
||||
<task active="true" id="Default" summary="Default task">
|
||||
<changelist id="21e926f9-529f-43a8-8440-6c9783336547" name="Default" comment="" />
|
||||
<created>1539091617637</created>
|
||||
<option name="number" value="Default" />
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1539091617637</updated>
|
||||
<workItem from="1539091621986" duration="5447000" />
|
||||
<workItem from="1539124194948" duration="24000" />
|
||||
<workItem from="1539623094436" duration="3705000" />
|
||||
<workItem from="1540161124567" duration="6321000" />
|
||||
<workItem from="1540438611626" duration="203000" />
|
||||
<workItem from="1541640190668" duration="8000" />
|
||||
<workItem from="1541732743102" duration="607000" />
|
||||
<workItem from="1541816906710" duration="166000" />
|
||||
<workItem from="1542116269451" duration="18000" />
|
||||
<workItem from="1542404479186" duration="10000" />
|
||||
<workItem from="1549338976965" duration="607000" />
|
||||
<workItem from="1554943052694" duration="135000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TimeTrackingManager">
|
||||
<option name="totallyTimeSpent" value="17251000" />
|
||||
</component>
|
||||
<component name="ToolWindowManager">
|
||||
<frame x="-7" y="0" width="1294" height="1092" extended-state="0" />
|
||||
<layout>
|
||||
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.24959481" />
|
||||
<window_info id="Structure" order="1" weight="0.25" />
|
||||
<window_info id="Image Layers" order="2" />
|
||||
<window_info id="Designer" order="3" />
|
||||
<window_info id="UI Designer" order="4" />
|
||||
<window_info id="Capture Tool" order="5" />
|
||||
<window_info id="Favorites" order="6" side_tool="true" />
|
||||
<window_info anchor="bottom" id="Docker" show_stripe_button="false" />
|
||||
<window_info anchor="bottom" id="Database Changes" />
|
||||
<window_info anchor="bottom" id="Message" order="0" />
|
||||
<window_info anchor="bottom" id="Find" order="1" />
|
||||
<window_info anchor="bottom" id="Run" order="2" />
|
||||
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
|
||||
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
|
||||
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
|
||||
<window_info anchor="bottom" id="TODO" order="6" />
|
||||
<window_info anchor="bottom" id="CheckStyle" order="7" />
|
||||
<window_info anchor="bottom" id="Terminal" order="8" />
|
||||
<window_info anchor="bottom" id="Event Log" order="9" side_tool="true" />
|
||||
<window_info anchor="bottom" id="Version Control" order="10" show_stripe_button="false" />
|
||||
<window_info anchor="right" id="Maven" />
|
||||
<window_info anchor="right" id="Commander" order="0" weight="0.4" />
|
||||
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
|
||||
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
|
||||
<window_info anchor="right" id="Palette" order="3" />
|
||||
<window_info anchor="right" id="Capture Analysis" order="4" />
|
||||
<window_info anchor="right" id="Theme Preview" order="5" />
|
||||
<window_info anchor="right" id="Database" order="6" />
|
||||
<window_info anchor="right" id="Palette	" order="7" />
|
||||
<window_info anchor="right" id="Maven Projects" order="8" />
|
||||
</layout>
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="1" />
|
||||
</component>
|
||||
<component name="editorHistoryManager">
|
||||
<entry file="file://$USER_HOME$/AppData/Local/Microsoft/Windows/INetCache/Content.Outlook/XUYNBAHD/LinkedList.java" />
|
||||
<entry file="file://$USER_HOME$/AppData/Local/Microsoft/Windows/INetCache/Content.Outlook/XUYNBAHD/ArrayList.java" />
|
||||
<entry file="file://$USER_HOME$/AppData/Local/Microsoft/Windows/INetCache/Content.Outlook/XUYNBAHD/Tester.java" />
|
||||
<entry file="file://$PROJECT_DIR$/src/barnestr/Tester.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="1285">
|
||||
<caret line="218" selection-start-line="218" selection-end-line="218" />
|
||||
<folding>
|
||||
<element signature="imports" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/barnestr/ArrayList.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="1598">
|
||||
<caret line="110" selection-start-line="110" selection-end-line="110" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/src/barnestr/LinkedList.java">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="2057">
|
||||
<caret line="132" column="13" selection-start-line="132" selection-start-column="13" selection-end-line="132" selection-end-column="13" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</component>
|
||||
<component name="masterDetails">
|
||||
<states>
|
||||
<state key="GlobalLibrariesConfigurable.UI">
|
||||
<settings>
|
||||
<splitter-proportions>
|
||||
<option name="proportions">
|
||||
<list>
|
||||
<option value="0.2" />
|
||||
</list>
|
||||
</option>
|
||||
</splitter-proportions>
|
||||
</settings>
|
||||
</state>
|
||||
<state key="JdkListConfigurable.UI">
|
||||
<settings>
|
||||
<last-edited>1.8</last-edited>
|
||||
<splitter-proportions>
|
||||
<option name="proportions">
|
||||
<list>
|
||||
<option value="0.2" />
|
||||
</list>
|
||||
</option>
|
||||
</splitter-proportions>
|
||||
</settings>
|
||||
</state>
|
||||
<state key="ProjectLibrariesConfigurable.UI">
|
||||
<settings>
|
||||
<splitter-proportions>
|
||||
<option name="proportions">
|
||||
<list>
|
||||
<option value="0.2" />
|
||||
</list>
|
||||
</option>
|
||||
</splitter-proportions>
|
||||
</settings>
|
||||
</state>
|
||||
</states>
|
||||
</component>
|
||||
</project>
|
||||
11
Labs/Lab 6/Lab 6.iml
Normal file
11
Labs/Lab 6/Lab 6.iml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
BIN
Labs/Lab 6/out/production/Lab 6/barnestr/ArrayList.class
Normal file
BIN
Labs/Lab 6/out/production/Lab 6/barnestr/ArrayList.class
Normal file
Binary file not shown.
BIN
Labs/Lab 6/out/production/Lab 6/barnestr/LinkedList$1.class
Normal file
BIN
Labs/Lab 6/out/production/Lab 6/barnestr/LinkedList$1.class
Normal file
Binary file not shown.
BIN
Labs/Lab 6/out/production/Lab 6/barnestr/LinkedList$Node.class
Normal file
BIN
Labs/Lab 6/out/production/Lab 6/barnestr/LinkedList$Node.class
Normal file
Binary file not shown.
BIN
Labs/Lab 6/out/production/Lab 6/barnestr/LinkedList.class
Normal file
BIN
Labs/Lab 6/out/production/Lab 6/barnestr/LinkedList.class
Normal file
Binary file not shown.
BIN
Labs/Lab 6/out/production/Lab 6/barnestr/Tester.class
Normal file
BIN
Labs/Lab 6/out/production/Lab 6/barnestr/Tester.class
Normal file
Binary file not shown.
201
Labs/Lab 6/src/barnestr/ArrayList.java
Normal file
201
Labs/Lab 6/src/barnestr/ArrayList.java
Normal file
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* CS2852
|
||||
* Spring 2018
|
||||
* Lab 6 - Recursion
|
||||
* Name:
|
||||
* Created: 4/13/2018
|
||||
*/
|
||||
package barnestr;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.RandomAccess;
|
||||
|
||||
/**
|
||||
* A partial implementation of an array-based List to be used
|
||||
* to practice implementing recursive methods.
|
||||
*
|
||||
* @param <E> The type of objects stored in the list
|
||||
*/
|
||||
public class ArrayList<E> implements List<E>, RandomAccess {
|
||||
private Object[] data;
|
||||
|
||||
/**
|
||||
* Constructs a list containing the elements of the specified collection,
|
||||
* in the order they are returned by the collection's iterator.
|
||||
* @param collection the collection whose elements are to be placed into this list
|
||||
* @throws NullPointerException - if the specified collection is null
|
||||
*/
|
||||
public ArrayList(Collection<? extends E> collection) {
|
||||
data = new Object[collection.size()];
|
||||
int index = 0;
|
||||
for(E element : collection) {
|
||||
data[index++] = element;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements in this list.
|
||||
* @return the number of elements in this list.
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return data.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this list contains the specified element.
|
||||
* <p></p>
|
||||
* More formally, returns <tt>true</tt> if and only if this list
|
||||
* contains at least one element <tt>e</tt> such that
|
||||
* <tt>(target==null ? e==null : target.equals(e))</tt>.
|
||||
* @param target element whose presence in the list is to be tested
|
||||
* @return true if the list contains the specified element
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(Object target) {
|
||||
boolean found = false;
|
||||
for(int i=0; !found && i<size(); ++i) {
|
||||
found = target==null ? data[i]==null : target.equals(data[i]);
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
// TODO
|
||||
private boolean contains(Object target, int position) {
|
||||
if (position > size()) {
|
||||
return false;
|
||||
} else {
|
||||
|
||||
contains(target, position + 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the first occurrence of the specified element
|
||||
* in this list, or -1 if this list does not contain the element.
|
||||
* <p></p>
|
||||
* More formally, returns the lowest index <tt>i</tt> such that
|
||||
* <tt>(target==null ? get(i)==null : target.equals(get(i)))</tt>,
|
||||
* or <tt>-1</tt> if there is no such index.
|
||||
* @param target element to search for
|
||||
* @return the index of the first occurrence of the specified element in this
|
||||
* list, or <tt>-1</tt> if this list does not contain the element
|
||||
*/
|
||||
@Override
|
||||
public int indexOf(Object target) {
|
||||
int index = -1;
|
||||
for(int i=0; index==-1 && i<size(); ++i) {
|
||||
if((target==null ? data[i]==null : target.equals(data[i]))) {
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public E get(int index) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public E set(int index, E element) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(E element) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, E element) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public E remove(int index) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object target) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray(T[] a) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends E> c) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, Collection<? extends E> c) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastIndexOf(Object o) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<E> listIterator() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<E> listIterator(int index) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<E> subList(int fromIndex, int toIndex) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
}
|
||||
267
Labs/Lab 6/src/barnestr/LinkedList.java
Normal file
267
Labs/Lab 6/src/barnestr/LinkedList.java
Normal file
@@ -0,0 +1,267 @@
|
||||
/*
|
||||
* CS2852
|
||||
* Spring 2018
|
||||
* Lab 6 - Recursion
|
||||
* Name:
|
||||
* Created: 4/13/2018
|
||||
*/
|
||||
package barnestr;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* A partial implementation of a singly linked list to be used
|
||||
* to practice implementing recursive methods.
|
||||
*
|
||||
* @param <E> The type of objects stored in the list
|
||||
*/
|
||||
public class LinkedList<E> implements List<E> {
|
||||
|
||||
private Node<E> head;
|
||||
private Node<E> tail;
|
||||
|
||||
/**
|
||||
* Inner class that describes a node in the singly linked list.
|
||||
*/
|
||||
private static class Node<E> {
|
||||
E value;
|
||||
Node<E> next;
|
||||
|
||||
/**
|
||||
* Constructs a node with a specified value and reference to the next node
|
||||
*
|
||||
* @param value Value of the element to be stored in the node
|
||||
* @param next Reference to the next element in the singly linked list
|
||||
*/
|
||||
private Node(E value, Node<E> next) {
|
||||
this.value = value;
|
||||
this.next = next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a node with a specified value
|
||||
*
|
||||
* @param value Value of the element to be stored in the node
|
||||
*/
|
||||
private Node(E value) {
|
||||
this(value, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a list containing the elements of the specified collection, in
|
||||
* the order they are returned by the collection's iterator.
|
||||
*
|
||||
* @param collection the collection whose elements are to be placed into this list
|
||||
* @NullPointerException if the specified collection is <tt>null</tt>
|
||||
*/
|
||||
public LinkedList(Collection<? extends E> collection) {
|
||||
Iterator<? extends E> itr = collection.iterator();
|
||||
if (itr.hasNext()) {
|
||||
head = new Node(itr.next());
|
||||
tail = head;
|
||||
}
|
||||
Node<E> walker = head;
|
||||
while (itr.hasNext()) {
|
||||
walker.next = new Node(itr.next());
|
||||
walker = walker.next;
|
||||
}
|
||||
tail = walker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of elements in this list
|
||||
*
|
||||
* @return the number of elements in this list
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
int size = 0;
|
||||
Node<E> walker = head;
|
||||
while (walker != null) {
|
||||
++size;
|
||||
walker = walker.next;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns true if this list contains the specified element.
|
||||
* <p></p>
|
||||
* More formally, returns <tt>true</tt> if and only if this list contains
|
||||
* at least one element <tt>e</tt> such that <tt>(o==null ? e==null : o.equals(e))</tt>.
|
||||
*
|
||||
* @param target element whose presence in this list is to be tested
|
||||
* @return true if this list contains the specified element
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(Object target) {
|
||||
Node<E> walker = head;
|
||||
boolean found = false;
|
||||
while (walker != null && !found) {
|
||||
found = target == null ? walker.value == null : target.equals(walker.value);
|
||||
walker = walker.next;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
// TODO
|
||||
private boolean contains(Object target, Node<E> position) {
|
||||
if (position == null) {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the first occurrence of the specified element in this list,
|
||||
* or <tt>-1</tt> if this list does not contain the element.
|
||||
* <p></p>
|
||||
* More formally, returns the lowest index <tt>i</tt> such that
|
||||
* <tt>(o==null ? get(i)==null : o.equals(get(i)))</tt>,
|
||||
* or <tt>-1</tt> if there is no such index.
|
||||
*
|
||||
* @param target element to search for
|
||||
* @return the index of the first occurrence of the specified element in this list,
|
||||
* or <tt>-1</tt> if this list does not contain the element
|
||||
*/
|
||||
@Override
|
||||
public int indexOf(Object target) {
|
||||
Node<E> walker = head;
|
||||
int index = -1;
|
||||
int counter = 0;
|
||||
while (walker != null && index == -1) {
|
||||
if (target == null ? walker.value == null : target.equals(walker.value)) {
|
||||
index = counter;
|
||||
}
|
||||
++counter;
|
||||
walker = walker.next;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the element at the specified position in this list.
|
||||
*
|
||||
* @param index index of the element to return
|
||||
* @return the element at the specified position in this list
|
||||
* @throws IndexOutOfBoundsException if the index is out of range
|
||||
* (index<0 || index>=size())
|
||||
*/
|
||||
@Override
|
||||
public E get(int index) {
|
||||
if (index < 0) {
|
||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size());
|
||||
}
|
||||
try {
|
||||
Node<E> walker = head;
|
||||
for (int i = 0; i < index; ++i) {
|
||||
walker = walker.next;
|
||||
}
|
||||
return walker.value;
|
||||
} catch (NullPointerException e) {
|
||||
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public E set(int index, E element) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(E element) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object target) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, E element) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public E remove(int index) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray(T[] a) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsAll(Collection<?> c) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends E> c) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, Collection<? extends E> c) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAll(Collection<?> c) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retainAll(Collection<?> c) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastIndexOf(Object o) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<E> listIterator() {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListIterator<E> listIterator(int index) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<E> subList(int fromIndex, int toIndex) {
|
||||
throw new UnsupportedOperationException("Not implemented");
|
||||
}
|
||||
|
||||
}
|
||||
218
Labs/Lab 6/src/barnestr/Tester.java
Normal file
218
Labs/Lab 6/src/barnestr/Tester.java
Normal file
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* CS2852
|
||||
* Spring 2017
|
||||
* Lab 6 - Recursion
|
||||
* Name:
|
||||
* Created: 3/30/2017
|
||||
*/
|
||||
package barnestr;
|
||||
|
||||
import javax.print.attribute.IntegerSyntax;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tests the ArrayList and LinkedList implementations for the
|
||||
* CS2852 Lab 6 assignment.
|
||||
*/
|
||||
public class Tester {
|
||||
private final static String[] EMPTY_STRINGS = {};
|
||||
private final static String[] STRINGS1 = {"this"};
|
||||
private final static String[] STRINGS2 = {"this", "will"};
|
||||
private final static String[] STRINGS3 = {"this", "will", "be"};
|
||||
private final static String[] STRINGS4 = {"this", "will", "be", "interesting"};
|
||||
private final static String[] STRINGS5 = {"this", null, "will", "be", "interesting"};
|
||||
|
||||
private final static int[] EMPTY_INTS = {};
|
||||
private final static int[] INTS1 = {-1};
|
||||
private final static int[] INTS2 = {-1, 2};
|
||||
private final static int[] INTS3 = {-1, 2, 8};
|
||||
private final static int[] INTS4 = {-1, 2, 8, Integer.MAX_VALUE};
|
||||
|
||||
/**
|
||||
* Calls all of the test methods
|
||||
* @param ignored Not used
|
||||
*/
|
||||
public static void main(String[] ignored) {
|
||||
String description = "ArrayList constructor collection of Strings of size: ";
|
||||
test(description + 0, stringConstructor(EMPTY_STRINGS));
|
||||
test(description + 1, stringConstructor(STRINGS1));
|
||||
test(description + 2, stringConstructor(STRINGS2));
|
||||
test(description + 3, stringConstructor(STRINGS3));
|
||||
test(description + 4, stringConstructor(STRINGS4));
|
||||
test(description + 5, stringConstructor(STRINGS5));
|
||||
|
||||
description = "ArrayList constructor collection of Integers of size: ";
|
||||
test(description + 0, intConstructor(EMPTY_INTS));
|
||||
test(description + 1, intConstructor(INTS1));
|
||||
test(description + 2, intConstructor(INTS2));
|
||||
test(description + 3, intConstructor(INTS3));
|
||||
test(description + 4, intConstructor(INTS4));
|
||||
|
||||
description = "ArrayList contains method for ArrayList of Integers of size: ";
|
||||
test(description + 0, arrayListContains(EMPTY_INTS));
|
||||
test(description + 1, arrayListContains(INTS1));
|
||||
test(description + 2, arrayListContains(INTS2));
|
||||
test(description + 3, arrayListContains(INTS3));
|
||||
test(description + 4, arrayListContains(INTS4));
|
||||
|
||||
description = "ArrayList indexOf method for ArrayList of Integers of size: ";
|
||||
test(description + 0, arrayListIndexOf(EMPTY_INTS));
|
||||
test(description + 1, arrayListIndexOf(INTS1));
|
||||
test(description + 2, arrayListIndexOf(INTS2));
|
||||
test(description + 3, arrayListIndexOf(INTS3));
|
||||
test(description + 4, arrayListIndexOf(INTS4));
|
||||
|
||||
description = "LinkedList size method for LinkedList of Integers of size: ";
|
||||
test(description + 0, linkedListSize(EMPTY_INTS));
|
||||
test(description + 1, linkedListSize(INTS1));
|
||||
test(description + 2, linkedListSize(INTS2));
|
||||
test(description + 3, linkedListSize(INTS3));
|
||||
test(description + 4, linkedListSize(INTS4));
|
||||
|
||||
description = "LinkedList contains method for LinkedList of Integers of size: ";
|
||||
test(description + 0, linkedListContains(EMPTY_INTS));
|
||||
test(description + 1, linkedListContains(INTS1));
|
||||
test(description + 2, linkedListContains(INTS2));
|
||||
test(description + 3, linkedListContains(INTS3));
|
||||
test(description + 4, linkedListContains(INTS4));
|
||||
|
||||
description = "LinkedList indexOf method for LinkedList of Integers of size: ";
|
||||
test(description + 0, linkedListIndexOf(EMPTY_INTS));
|
||||
test(description + 1, linkedListIndexOf(INTS1));
|
||||
test(description + 2, linkedListIndexOf(INTS2));
|
||||
test(description + 3, linkedListIndexOf(INTS3));
|
||||
test(description + 4, linkedListIndexOf(INTS4));
|
||||
|
||||
description = "LinkedList get method method for LinkedList of Integers of size: ";
|
||||
test(description + 0, linkedListGet(EMPTY_INTS));
|
||||
test(description + 1, linkedListGet(INTS1));
|
||||
test(description + 2, linkedListGet(INTS2));
|
||||
test(description + 3, linkedListGet(INTS3));
|
||||
test(description + 4, linkedListGet(INTS4));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays an error if the test fails
|
||||
* @param description Description of the test
|
||||
* @param passed true if the test passed
|
||||
*/
|
||||
private static void test(String description, boolean passed) {
|
||||
if(!passed) {
|
||||
System.out.println("Test failed: " + description);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the constructor that accepts a collection of elements.
|
||||
* After the ArrayList is instantiated, the size is compared with
|
||||
* the size of the collection.
|
||||
* @param strings An array of Strings to be added to the ArrayList
|
||||
* @return true if test passed
|
||||
*/
|
||||
private static boolean stringConstructor(String[] strings) {
|
||||
Collection<String> input = new java.util.ArrayList<>();
|
||||
for(String string : strings) {
|
||||
input.add(string);
|
||||
}
|
||||
List<String> list = new ArrayList<>(input);
|
||||
return list.size()==input.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the constructor that accepts a collection of elements.
|
||||
* After the ArrayList is instantiated, the size is compared with
|
||||
* the size of the collection.
|
||||
* @param numbers An array of ints to be added to the ArrayList
|
||||
* @return true if test passed
|
||||
*/
|
||||
private static boolean intConstructor(int[] numbers) {
|
||||
Collection<Integer> input = new java.util.ArrayList<>();
|
||||
for(int number : numbers) {
|
||||
input.add(number);
|
||||
}
|
||||
List<Integer> list = new ArrayList<>(input);
|
||||
return list.size()==input.size();
|
||||
}
|
||||
|
||||
private static boolean arrayListContains(int[] numbers) {
|
||||
List<Integer> input = new java.util.ArrayList<>();
|
||||
for (int num : numbers) {
|
||||
input.add(num);
|
||||
}
|
||||
List<Integer> list = new ArrayList<>(input);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if (!(input.contains(input.get(i)) ||
|
||||
list.contains(list.get(i)))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean arrayListIndexOf(int[] numbers) {
|
||||
List<Integer> input = new java.util.ArrayList<>();
|
||||
for (int num : numbers) {
|
||||
input.add(num);
|
||||
}
|
||||
List<Integer> list = new barnestr.ArrayList<>(input);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
return list.indexOf(list.get(i)) == input.indexOf(input.get(i));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean linkedListSize(int[] numbers) {
|
||||
Collection<Integer> input = new java.util.LinkedList<>();
|
||||
for (int num : numbers) {
|
||||
input.add(num);
|
||||
}
|
||||
List<Integer> list = new LinkedList<>(input);
|
||||
return list.size() == input.size();
|
||||
}
|
||||
|
||||
private static boolean linkedListContains(int[] numbers) {
|
||||
List<Integer> input = new java.util.LinkedList<>();
|
||||
for (int num : numbers) {
|
||||
input.add(num);
|
||||
}
|
||||
List<Integer> list = new LinkedList<>(input);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if (!(input.contains(input.get(i)) ||
|
||||
list.contains(list.get(i)))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean linkedListIndexOf(int[] numbers) {
|
||||
List<Integer> input = new java.util.LinkedList<>();
|
||||
for (int num : numbers) {
|
||||
input.add(num);
|
||||
}
|
||||
List<Integer> list = new LinkedList<>(input);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
return list.indexOf(list.get(i)) == input.indexOf(input.get(i));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean linkedListGet(int[] numbers) {
|
||||
java.util.LinkedList<Integer> input = new java.util.LinkedList<>();
|
||||
for (int num : numbers) {
|
||||
input.add(num);
|
||||
}
|
||||
List<Integer> list = new LinkedList<>(input);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if (input.get(i) != list.get(i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
BIN
Labs/Lab 6/src/barnestr/barnestr.zip
Normal file
BIN
Labs/Lab 6/src/barnestr/barnestr.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user