toString why you be so stubborn

This commit is contained in:
2025-10-19 21:31:19 -05:00
parent 8d434d7245
commit f561991539
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