toString why you be so stubborn

This commit is contained in:
2023-11-06 13:26:35 -06:00
parent 643bdc658f
commit 9cc7e1d0df
4 changed files with 80 additions and 3 deletions

View File

@@ -0,0 +1,16 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package linkedlist;
/**
*
* @author caleb
*/
public class EmptyListException extends RuntimeException{
public EmptyListException() {}
public EmptyListException(String msg) {
super(msg);
}
}

View File

@@ -103,10 +103,13 @@ public class MyList<E> {
}
public E removeAt(int index) {
if (size() == 0) {
throw new EmptyListException("The list is empty.");
}
if (index < 0 || index >= size())
throw new IndexOutOfBoundsException();
if (size() == 0)
throw new RuntimeException("Empty List");
throw new EmptyListException("Empty List");
E removedE = null;
if (index == 0) {
// remove the front