All pastes #768204 Raw Edit

Something

public text v1 · immutable
·published 2007-11-10 11:59 UTC
rendered paste body
public class DLinkedListImpl<E> implements DLinkedList<E> {

	private static class Node<E> 
	{
		E value;
		Node prev;
		Node next;
		
		Node(E eValue)
		{
			value = eValue;
			prev = null;
			next = null;
		}
	}
	
	Node head;
	Node tail;
	
	public DLinkedListImpl()
	{
		head = new Node<E>();
		tail = new Node<E>();
		
		head.next = tail;
		tail.prev = head;
	}
	
	public void add(E e) 
	{
		Node temp = new Node(e);
		temp.prev = tail.prev;
		temp.next = tail;
		
		(temp.prev).next = temp;
		tail.prev = temp;
		
		return;
	}

	public boolean contains(E e)
	{
		Node temp = head.next;
		
		while(temp != null)
		{
			if (temp.value = e)
			{
				return true;
			}
		}
		
		return false;
	}
	
	public printList(void)
	{
		Node temp = head.next;
		
		while(temp != null)
		{
			System.out.println(temp.value + "\n");
		}
		
		return;
	}

	public static void main(String[] args)
	{
		DLinkedListImpl<String> a = new DLinkedListImpl<String>();
		a.add("A");
		a.add("B");
		a.add("C");
		
		a.printList();
		
		return;
	}
}