
// Modela un vector asociativo o no asociativo.
function Clase_Vector(){ 
	   // Modela vector no asociativo
	   this.elementos = new Array();
	   //
	   
	   // Modela vector asociativo
       this.claves = new Array();
	   this.valores = new Array();
	   //
	   
	   this.n_elementos = 0;
	   this.addIndexValue = addIndexValue;
	   this.addFistIndexValue = addFistIndexValue;
	   this.addKeyValue = addKeyValue;
	   this.setValueKey = setValueKey;
	   this.deleteKeyValue = deleteKeyValue;
	   this.deleteIndex = deleteIndex;
	   this.setIndexValue = setIndexValue;
	   this.getIndexValue = getIndexValue;
	   this.getFirstIndexValue = getFirstIndexValue;
	   this.getArray = getArray;
	   this.getIndexKey = getIndexKey;
	   this.getIndexElemento = getIndexElemento;
	   this.getKey = getKey;
	   this.getValueOf = getValueOf;
	   this.getNumberElements = getNumberElements;
	   this.writeAll = writeAll;
	   this.isKey = isKey;
	   this.isContain = isContain;
}

// A&ntilde;ade en la colecci&oacute;n un valor
function addIndexValue(valor){
	this.elementos[this.n_elementos] = valor;
	this.n_elementos++;
}

// A&ntilde;ade en la colecci&oacute;n un valor, pero siempre al inicio de la lista
function addFistIndexValue(valor){
	for (i=n_elementos;i>0;i--){
		this.elementos[i] = this.elementos[i-1];
	}
	this.elementos[0] = valor;
	this.n_elementos++;
}

// A&ntilde;ade un par clave -> valor
function addKeyValue(key,value){
	this.claves[this.n_elementos] = key;
	this.valores[this.n_elementos] = value;
	this.n_elementos++;
}

// Elimina el elemento valor del vector no asociativo
function deleteIndex(valor){
	var index = this.getIndexElemento(valor);
	for (i=index;i<this.n_elementos;i++){
		this.elementos[i] = this.elementos[i+1];
	}
	this.n_elementos--;
}

// Elimina un par clave -> valor en el vector asociativo
function deleteKeyValue(key){
	var indexKey = this.getIndexKey(key);
	for (i=indexKey;i<this.n_elementos;i++){
		this.claves[i] = this.claves[i+1];
		this.valores[i] = this.valores[i+1];
	}
	this.n_elementos--;
}

// Actualizo el valor de la clave key
function setValueKey(key,value){
	var index = this.getIndexKey(key);
	this.valores[index] = value;
}

// A&ntilde;ado en el vector no asociativo el elemento 'e' en la posicion i
function setIndexValue(e,i){
	this.elementos[i] = e;
}

// Obtenemos el elemento i del vector no asociativo
function getIndexValue(i){
	//alert(i+": "+this.elementos[i]);
	return this.elementos[i];
}

// Obtenemos el elemento i INSERTADO usando addFirstIndexValue
function getFirstIndexValue(i){
	return this.elementos[n_elementos-i-1];
}

// Obtenemos el vector no asociativo
function getArray(){
	return this.elementos;
}

// Obtenemos el &iacute;ndice que ocupa la clave key
function getIndexKey(key){
	for (i=0;i<this.n_elementos;i++){
		if (this.claves[i]==key){
			return i;
		}
	}
	return -1;
}

// Obtenemos el &iacute;ndice que ocupa el elemento en el vector no asociativo
function getIndexElemento(elemento){
	for (i=0;i<this.n_elementos;i++){
		if (this.elementos[i]==elemento){
			return i;
		}
	}
	return -1;
}

// Obtenemos la clave i
function getKey(i){
	return this.claves[i];
}

//Obtenemos el valor de la clave key
function getValueOf(key){
	for (i=0;i<this.n_elementos;i++){
		if (this.claves[i]==key){
			return this.valores[i];
		}
	}
	return "";
}

//Obtenemos el n&uacute;mero de elementos del vector, asociativo o no
function getNumberElements(){
	return this.n_elementos;
}

//Escribe todos los elementos del vector no asociativo
function writeAll(){
}

//Indica si key es clave del vector asociativo
function isKey(key){
	for (i=0;i<this.n_elementos;i++){
		if (this.claves[i]==key){
			return true;
		}
	}
	return false;
}

//Indica si existe el elemento en el vector no asociativo
function isContain(elemento){
	for (i=0;i<this.n_elementos;i++){
		if (this.elementos[i]==elemento){
			return true;
		}
	}
	return false;
}
