function array_to_linked_list(a){

	list = new LinkedList();

	for(i=0; i<a.length; i++){
		list_item = new LinkedListItem();
		list_item.content = a[i];

		list.addToTail(list_item);
	}

	return list;
}


function LinkedListItem(){
	this.content = null;
	this.next = null;
	this.prev = null;
}

function LinkedList(){
	this.head = null;
	this.tail = null;

	this.addToHead = function(item){
		
		if(this.head != null)
			this.head.prev = item;

		item.next = this.head;
		this.head = item;

		if(this.head.next == null && this.tail == null)
			this.tail = this.head;
	}

	this.addToTail = function(item){

		if(this.tail != null)
			this.tail.next = item;

		item.prev = this.tail;
		this.tail = item;

		if(this.tail.prev == null && this.head == null)
			this.head = this.tail;
	}

	this.removeFromHead = function(){
	
		var item = null;

		if(this.head != null){
			item = this.head.content;
			this.head = this.head.next;
			if(this.head != null)
				this.head.prev = null;
		}	

		return item;

	}

	this.removeFromTail = function(){
	
		var item = null;

		if(this.tail != null){
			item = this.tail.content;
			this.tail = this.tail.prev;
			if(this.tail != null)
				this.tail.next = null;
		}	

		return item;

	}

	this.toString = function(){
		var item = this.head;
		var s = "";

		while(item != null){
			s += " " + item.content;
			item = item.next;
		}

		return s;
	}

}

