var LinkedList = new Class.create();

LinkedList.prototype = {
	initialize: function() {
		this.elem = null;
		this.next = null;
	},
	
	addIn:	function(elem,i) {
		if(i == 0) {
			this.elem = elem;
			this.next = new LinkedList();
		} else {
			this.next.add(elem,i-1);
		}
	},
	
	add:		function(elem) {
		this.addIn(elem,this.size());
	},
	
	get:		function(index) {
		if(index == 0) {
			return this.elem;
		} else {
			return this.next.get(index-1);
		}
	}, 
	
	set:		function(index, elem) {
		if(index == 0) {
			this.elem = elem;
		} else {
			this.next.set(index-1,elem);
		}
	}, 
	
	size:		function() {
		if(this.next == null) {
			if(this.elem == null) {
				return 0;
			} else {
				return 1;
			}
		} else {
			return (this.next.size()+1)
		}
	},
	
	isEmpty:	function() {
		return (this.size() == 0);
	}, 
	
	remove:		function(elem) {
		if(this.elem == elem) {
			this.elem = this.next.elem;
			this.next = this.next.next;
		} else {
			this.next.remove(elem);
			
		}
	},
	
	exists:		function(elem) {
		if(this.elem == elem) {
			return true;
		} else {
			if(this.next != null) {
				return this.next.exists(elem);
			} else {
				return false
			}
		}
	},
	
	subList:	function(start,end) {
		var result = new LinkedList();
		var i = start;
		for(i=start;i<=end;i++) {
			//alert(i);
			result.add(this.get(i));
		}
		return result;
	}
};

