public class Vector<t>
{
t[] _vec;
int _noElems;
public Vector()
{
_vec = new t[0];
_noElems = 0;
}
public Vector(int size)
{
_vec = new t[size];
_noElems = size;
}
public double GetAverage()
{
double a = 0;
for (int i = 0; i < _noElems; i++)
a += Convert.ToDouble(_vec[i]);
a /= _noElems;
return a;
}
public void Add(t value)
{
t[] temp = new t[_vec.Length + 1];
for (int i = 0; i < _vec.Length; i++)
temp[i] = _vec[i];
temp[temp.Length - 1] = value;
_noElems++;
_vec = null;
_vec = temp;
temp = null;
}
public int NoElems
{
get { return _noElems; }
}
public override string ToString()
{
StringBuilder s = new StringBuilder();
for (int i = 0; i < _vec.Length; i++)
s.Append(_vec[i].ToString() + " ,");
return s.ToString();
}
public t this[int index]
{
get { return _vec[index]; }
set { _vec[index] = value; }
}
public t GetMax()
{
t n;
t m = _vec[0];
for (int i = 1; i < _vec.Length; i++)
{
n = _vec[i];
if (Convert.ToDouble(n) > Convert.ToDouble(m))
m = n;
}
return m;
}
public t GetMin()
{
t n;
t m = _vec[0];
for (int i = 1; i < _vec.Length; i++)
{
n = _vec[i];
if (Convert.ToDouble(n) < Convert.ToDouble(m))
m = n;
}
return m;
}
Al mismo tiempo la utilizamos para un pequeño programa que calcula información acerca de calificaciones de alumnos:
http://www.mediafire.com/?32g7drfox9fscvi

No hay comentarios:
Publicar un comentario