This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.junit.Assert.*; | |
import org.junit.Test; | |
import org.junit.Before; | |
import java.util.ArrayList; | |
/** | |
* Linked List Tests | |
* @author Chintan |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assertTrue(list.remove(0).equals(j)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public E remove(int index) throws IndexOutOfBoundsException{ | |
if (index >= size || index < 0) throw new IndexOutOfBoundsException(); | |
Node<E> prev = null, temp = head; | |
E data; | |
int a = 0; | |
// Set temp to the node to be deleted | |
while(a != index) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public E remove(int index) throws IndexOutOfBoundsException{ | |
if (index >= size || index < 0) throw new IndexOutOfBoundsException(); | |
Node<E> prev = null, temp = head; | |
E data; | |
int a = 0; | |
// Set temp to the node to be deleted | |
while(a != index) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testRemoveInt() { | |
list.add(i); | |
list.add(j); | |
assertTrue(list.remove(0).equals(i)); | |
assertFalse(list.getHead().equals(i)); | |
System.out.println(list.getHead().getData()); | |
assertTrue(list.getHead().equals(j)); | |
assertTrue(list.remove(0).equals(j)); | |
assertTrue(list.getHead() == null); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public E remove(int index) throws IndexOutOfBoundsException{ | |
if (index >= size || index < 0) throw new IndexOutOfBoundsException(); | |
Node<E> prev = null, temp = head; | |
E data; | |
int a = 0; | |
// Set temp to the node to be deleted | |
while(a != index) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Collection; | |
/** | |
* This is a circular, singly linked list. | |
*/ | |
public class LinkedList<E> implements List<E> { | |
protected Node<E> head; | |
protected Node<E> tail; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testRemoveInt() { | |
list.add(i); | |
list.add(j); | |
assertTrue(list.remove(0).equals(i)); | |
assertFalse(list.getHead().equals(i)); | |
assertTrue(list.getHead().equals(j)); | |
assertTrue(list.remove(0).equals(j)); | |
assertTrue(list.getHead() == null); | |
list.add(i); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public E remove(int index) throws IndexOutOfBoundsException{ | |
if (index >= size || index < 0) throw new IndexOutOfBoundsException(); | |
Node<E> prev = null, temp = head; | |
E data; | |
int a = 0; | |
// Set temp to the node to be deleted | |
while(a != index) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Collection; | |
/** | |
* This is a circular, singly linked list. | |
*/ | |
public class LinkedList<E> implements List<E> { | |
protected Node<E> head; | |
protected Node<E> tail; |