Skip to content

Instantly share code, notes, and snippets.

View chintanparikh's full-sized avatar
🎯
Focusing

Chintan Parikh chintanparikh

🎯
Focusing
View GitHub Profile
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.Before;
import java.util.ArrayList;
/**
* Linked List Tests
* @author Chintan
assertTrue(list.remove(0).equals(j));
@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)
@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)
@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);
@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)
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;
@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);
@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)
@chintanparikh
chintanparikh / LinkedList.java
Created January 17, 2013 21:19
Linked List
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;