Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished all code and tests #12

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c255f6b
implementing methods
AddisonFarley Jan 4, 2024
cd074ee
finished addFront and addBack
AddisonFarley Jan 4, 2024
8f26ee0
finished get and size
AddisonFarley Jan 4, 2024
d6e1338
finished remove and contains methods
AddisonFarley Jan 9, 2024
87b67b2
created private resize method. finished clear and isEmpty. Started on…
AddisonFarley Jan 9, 2024
e1fac91
created private sizeCheck method and put into all add methods
AddisonFarley Jan 9, 2024
e8a9ab6
created private sizeCheck method and put into all add methods
AddisonFarley Jan 9, 2024
7eb802a
Created LinkedIntList.java and DoublyLinkedIntList.java
AddisonFarley Jan 16, 2024
dbee766
completed addBack() and removeBack() for DoublyLinkedIntList.java
AddisonFarley Jan 16, 2024
94495ae
completed iterator methods and classes for ArrayIntList.java and Link…
AddisonFarley Jan 18, 2024
adc28d5
finished all methods
AddisonFarley Jan 22, 2024
9f3af36
fixed traversal bugs
AddisonFarley Jan 22, 2024
01370c5
finished LinkedIntList.java methods
AddisonFarley Jan 22, 2024
a8ca925
fixed indexOutOfBoundsChecker bug
AddisonFarley Jan 22, 2024
1749a31
finished ArrayIntList.java methods
AddisonFarley Jan 22, 2024
231856a
fixed bugs in addFront(), removeFront(), remove(), and size()
AddisonFarley Jan 22, 2024
06da242
created test files
AddisonFarley Jan 22, 2024
149b8e3
created ArrayIntList.java tests
AddisonFarley Jan 22, 2024
eb4bed3
fixed bugs in removeFront() and removeBack()
AddisonFarley Jan 22, 2024
4e8346a
fixed multiple bugs
AddisonFarley Jan 22, 2024
a0db349
created tests
AddisonFarley Jan 22, 2024
7646bfc
fixed bugs added more comments
AddisonFarley Jan 22, 2024
153aa70
fixed bugs in DoublyLinkedIntList.java, created tests for DoublyLinke…
AddisonFarley Jan 24, 2024
cef78c5
added iterator for DoublyLinkedIntList.java
AddisonFarley Jan 24, 2024
1875f04
forgot testing of resizing
AddisonFarley Jan 24, 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
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions IntListReview.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>
289 changes: 289 additions & 0 deletions src/ArrayIntList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,289 @@
import java.util.Iterator;
import java.util.NoSuchElementException;

public class ArrayIntList implements IntList
{
//fields
private int size;
private int[] buffer;

public ArrayIntList()
{
size = 0;
buffer = new int[10];
}

private void resize(int newSize)
{
int[] newBuffer = new int[newSize];

for (int i = 0; i < buffer.length; i++)
{
newBuffer[i] = buffer[i];
}

buffer = newBuffer;
}

private void sizeCheck()
{
if (size == buffer.length)
{
resize(size * 2);
}
}

/**
* Prepends (inserts) the specified value at the front of the list (at index 0).
* Shifts the value currently at the front of the list (if any) and any
* subsequent values to the right.
*
* @param value value to be inserted
*/
@Override
public void addFront(int value)
{
sizeCheck();

for (int i = size; i > 0; i--)
{
buffer[i] = buffer[i - 1];
}

buffer[0] = value;
size++;
}

/**
* Appends (inserts) the specified value at the back of the list (at index size()-1).
*
* @param value value to be inserted
*/
@Override
public void addBack(int value)
{
sizeCheck();

buffer[size] = value;
size++;
}

/**
* Inserts the specified value at the specified position in this list.
* Shifts the value currently at that position (if any) and any subsequent
* values to the right.
*
* @param index index at which the specified value is to be inserted
* @param value value to be inserted
* @throws IndexOutOfBoundsException if the index is out of range
*/
@Override
public void add(int index, int value)
{
sizeCheck();
}

/**
* Removes the value located at the front of the list
* (at index 0), if it is present.
* Shifts any subsequent values to the left.
*/
@Override
public void removeFront()
{
if (size > 0)
{
for (int i = 0; i < size - 1; i++)
{
buffer[i] = buffer[i + 1];
}
size--;
}
}

/**
* Removes the value located at the back of the list
* (at index size()-1), if it is present.
*/
@Override
public void removeBack()
{
if (size > 0)
{
size--;
buffer[size] = 0;
}
}

/**
* Removes the value at the specified position in this list.
* Shifts any subsequent values to the left. Returns the value
* that was removed from the list.
*
* @param index the index of the value to be removed
* @return the value previously at the specified position
* @throws IndexOutOfBoundsException if the index is out of range
*/
@Override
public int remove(int index)
{
indexOutOfBoundsChecker(index);

int removedValue = buffer[index];

//shift all to left
for (int i = index; i < size - 1; i++)
{
buffer[i] = buffer[i + 1];
}

size--;

return removedValue;
}

/**
* Returns the value at the specified position in the list.
*
* @param index index of the value to return
* @return the value at the specified position in this list
* @throws IndexOutOfBoundsException if the index is out of range
*/
@Override
public int get(int index)
{
indexOutOfBoundsChecker(index);

return buffer[index];
}

/**
* Returns true if this list contains the specified value.
*
* @param value value whose presence in this list is to be searched for
* @return true if this list contains the specified value
*/
@Override
public boolean contains(int value)
{
for (int num:buffer)
{
if (num == value)
{
return true;
}
}
return false;
}

/**
* Returns the index of the first occurrence of the specified value
* in this list, or -1 if this list does not contain the value.
*
* @param value value to search for
* @return the index of the first occurrence of the specified value in this list
* or -1 if this list does not contain the value
*/
@Override
public int indexOf(int value)
{
//helper
int currIndex = 0;

for(int val:buffer)
{
if(val == value)
{
//return index value was found at
return currIndex;
}

//increment currIndex
currIndex++;
}

//value not found
return -1;
}

/**
* Returns true if this list contains no values.
*
* @return true if this list contains no values
*/
@Override
public boolean isEmpty()
{
return size == 0;
}

/**
* Returns the number of values in this list.
*
* @return the number of values in this list
*/
@Override
public int size()
{
return size;
}

/**
* Removes all the values from this list.
* The list will be empty after this call returns.
*/
@Override
public void clear()
{
buffer = new int[10];

size = 0;
}


@Override
public Iterator<Integer> iterator()
{
return new IntListIterator();
}

//create private helper iterator class
private class IntListIterator implements Iterator<Integer>
{
private int i;

public IntListIterator()
{
i = 0;
}


@Override
public boolean hasNext()
{
return i < size;
}


@Override
public Integer next()
{
if (i >= size)
{
throw new NoSuchElementException("i is out of bounds");
}

int curr = buffer[i];
i++;
return curr;
}
}

private void indexOutOfBoundsChecker(int index)
{
if(index >= size || size < 0)
{
throw new IndexOutOfBoundsException("Index out of range");
}
}
}
Loading