You are on page 1of 6

Prctico del Tema 5 Listas Grupo N 11

MATERIA GRUPO DOCENTE FECHA

: PROGRAMACION I : N 11 : ING. EDWIN VARGAS YAPURA : 24/06/2013

programa principal: int x=5; Lista l1 = new Lista(100); l1.adicionar(3); l1.adicionar(2); l1.adicionar(3); System.out.println(l1); System.out.println(l1.diferentes()); System.out.println(l1.mayor()); System.out.println(l1.puroPares()); System.out.println("es palindrome?"+l1.palindrome()); l1.mayor(); l1.menor(); l1.suma1(); l1.suma2(); l1.promedio(); l1.menoresProm(); l1.mayoresProm(); l1.ordenado(); l1.frecuencia(x); l1.iguales(); l1.diferentes(); l1.palindrome(); l1.puroPares(); --------------------------------------------------------public class Lista { private int elem[]; private int CantElem; private int max; public Lista (int max) { this.max = max; elem = new int [max]; this.CantElem = 0; } public String ToString() { String s1 = "["; int i = 0; while (i < this.CantElem) { if (i == this.CantElem)s1 = s1 + this.elem[i]; else s1 = s1 + this.elem[i]+", "; i=i+1; } return s1;

} public void adicionar(int x) { this.elem[this.CantElem] = x; this.CantElem = this.CantElem + 1; } public int menor() { int i=0, me=this.elem[0]; while (i < this.CantElem) { if (this.elem[i] < me) me = this.elem[i]; i=i+1; } return me; }

public int mayor() { int i=0, my=this.elem[0]; while (i < this.CantElem) { if (this.elem[i] > my) my = this.elem[i]; i=i+1; } return my; } public int suma1() { int i,sum; i=0; sum=0; while (i < this.CantElem) { sum = sum + this.elem[i]; i=i+1; } return sum; } public int suma2() { int i,j,s; i=0; j=CantElem; s=0; while (i<j) { s=s+elem[i]+elem[j]; i=i+1; j=j-1;

} return s; } public int promedio() { return suma1()/CantElem; } public int menoresProm() { int i,c; i=0;c=0; while (i<CantElem) { if (elem[i] < promedio()) c=c+1; i=i+1; } return c; } public int mayoresProm() { int i,c; i=0;c=0; while (i<CantElem) { if (elem[i] > promedio()) c=c+1; i=i+1; } return c; } public boolean ordenado() { int i=0; boolean sw=true; while (i<CantElem && sw) { if (elem[i] > elem[i+1]) sw=false; i=i+1; } return sw; }

public int frecuencia(int x) { int i=0,c=0; while (i<this.CantElem) { if (this.elem[i] == x) c = c+1; i=i+1; }

return c; }

public boolean iguales() { return this.frecuencia(this.elem[0]) == this.CantElem; } public boolean diferentes() { int i=0; while (i < this.elem[i]) { if (this.frecuencia(this.elem[i]) > 1) return false; i=i+1; } return true; } public int sumapares() { int sm=0; int i=0; while(i<this.cantele) { if(this.ele[i]/2==0)sm=sm+this.ele[i]; i=i+1; } return sm; } public int sumaimpares() { int sm=0; int i=0; while(i<this.cantele) { if((this.ele[i] % 2 != 0)) sm=sm+this.ele[i]; i= i + 1; } return sm; } public boolean palindrome(){ int i=0, j=this.CantElem -1; while (i < j){ if (this.elem[i] != this.elem[j]) return false;

i=i+1; j=j-1; } return true; } public boolean puroPares(){ int i,j; i=0; j = CantElem; while(i < j){ if (this.elem[i] % 2 != 0) return false; i=i+1; } return true; } }