/**
 * @author mitsunoriogihara
 *
 */
public class LinkedListExample<E> {

	/**
	 * internal class
	 * @author mitsunori ogihara
	 *
	 * @param <E>
	 */
	private class Node<E> {
		// data fields
		private E data;
		private Node<E> next;
		private Node<E> prev;
		
		Node(E data) {
			this.data = data;
			this.next = null;
			this.prev = null;
		}
	}
	
	Node<E> head;
	Node<E> tail;
	int size;
	
	LinkedListExample() {
		size = 0;
		head = null;
		tail = null;
	}
	LinkedListExample(E... dataList) {
		size = dataList.length;
		if (size==0) {
			head = null;
			tail = null;
		}
		else {
			Node<E> current = null;
			int position = 0;
			for (E data : dataList) {
				Node<E> newGuy = new Node<E>(data);
				if (position==0) {
					head = newGuy;
					current = newGuy;
				}
				else {
					current.next = newGuy;
					newGuy.prev = current;
					current = newGuy;
				}
				position++;
			}
			tail = current;
		}
	}
	public void addLast(E data) {
	}
	public void addFirst(E data) {
	}
	public void add(int position, E data) {
		if (position==0) addFirst(data);
		else if (position==size) addLast(data);
		else if (position>0 && position<size) {
			Node<E> current = head;
			for (int i=0; i<position-1; i++) {
				current = current.next;
			}
			Node<E> newGuy = new Node<E>(data);
			newGuy.next = current.next;
			current.next.prev = newGuy;
			newGuy.prev = current;
			current.next = newGuy;
			size++;
		}
	}
	
	public void addWrong(int position, E data) {
		if (position==0) addFirst(data);
		else if (position==size) addLast(data);
		else if (position>0 && position<size) {
			Node<E> current = head;
			for (int i=0; i<position-1; i++) {
				current = current.next;
			}
			Node<E> newGuy = new Node<E>(data);

			newGuy.prev = current;
			current.next = newGuy;
			
			newGuy.next = current.next;
			current.next.prev = newGuy;

			size++;
		}
	}
	
	
	
	public void remove(int position) {
	}
	public void print() {
		Node<E> current = head;
		int i=0;
		while (current!=null && i<size) {
			System.out.println("Element "+i+" = "+current.data.toString());
			current = current.next;
			i++;
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		LinkedListExample<String> myList = new LinkedListExample<String>(
				"Troy Polamalu", "Brett Favre", "Ray Rice", "Chris Johnson",
				"Clay Mathews", "Darrell Revis");
		myList.addWrong(3,"Joseph Addai");
		myList.addWrong(3,"Adam Vinatieri");
		myList.remove(0);
		myList.print();
		
	}

}
