
// 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.isKeyClon = isKeyClon;
	   this.isContain = isContain;
}

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

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

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

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

// Elimina un par clave -> valor en el vector asociativo
function deleteKeyValue(key){
	var indexKey = this.getIndexKey(key);
	var dK=0;
	for (dK=indexKey;dK<this.n_elementos;dK++){
		this.claves[dK] = this.claves[dK+1];
		this.valores[dK] = this.valores[dK+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ñ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 índice que ocupa la clave key
function getIndexKey(key){
	var gI = 0;
	for (gI=0;gI<this.n_elementos;gI++){
		if (this.claves[gI]==key){
			return gI;
		}
	}
	return -1;
}

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

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

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

//Obtenemos el nú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){
	var iK = 0;
	for (iK=0;iK<this.n_elementos;iK++){
		if (this.claves[iK]==key){
			return true;
		}
	}
	return false;
}

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


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