Aqui esta el
ejercicio
No 2 el motivo por que lo publico aqui es que cuando publico en el blog se borra parte del codigo lo intente muchas veces y fui a diferentes internets pero nada, se me borraba, cuando puse en vista previa se borraba mmm
Aki esta :
Ejercicio No 2 :
import java.util.Scanner;
public class Prueva{
public static void main( String arg[]){
Pila p1=new Pila();
Pila p2=new Pila();
Pila p3=new Pila();
Pila p4=new Pila();
Scanner sc=new Scanner(System.in);
int n1,numero;
System.out.println("Cuantos datos decea ingresar?" );
n1=sc.nextInt();
System.out.println("Ingrese los datos:" );
for(int i=0;i<n1;i++)
{numero=sc.nextInt();
p1.push(numero);
}
int cont=0,aux1=0;
while(!p1.isEmpty()){
int aux=p1.pop();
p4.push(aux);
aux1=aux1+aux;
cont++;
}
int promedio=aux1/cont;
while(!p4.isEmpty()){ int aux=p4.pop();
if(aux>promedio){p2.push(aux); }
if(aux<promedio){p3.push(aux); }
}
System.out.println("Datos mayores al promedio"+" "+promedio+" "+"son:" );
while(!p2.isEmpty()){ System.out.println(p2.pop());
}
System.out.println("Datos menores al promedio"+" "+promedio+" "+"son:" );
while(!p3.isEmpty()){System.out.println(p3.pop()); }
}
}
Las demas Clases :
class Nodo{
int info;
Nodo enlace;
public Nodo(int a){
info=a;
enlace=null;
}
}
La clase Pila :
class Pila{
Nodo first,top;
boolean isEmpty(){
if(first==null)
return true;
else
return false;
}
void push(int a){
if(isEmpty())
{first=new Nodo(a);
top=first;
}
else{
Nodo temp=new Nodo(a);
top.enlace=temp;
top=temp;
}
}
int pop(){
int aux;
if(isEmpty())
return -1;
else
{
if(first.enlace==null){
aux=first.info;
first=null;
top=null;
}
else{ Nodo temp=first;
while(temp.enlace!=top){
temp=temp.enlace; }
aux=top.info;
temp.enlace=null;
top=temp;
}
}
return aux;
}
int peek(){
if(isEmpty())
return -1;
else
return top.info;
}
}
Atte ; Willians Melchor Huarachi
Si no me creen ya publico fotos XD
Aki esta :
Ejercicio No 2 :
import java.util.Scanner;
public class Prueva{
public static void main( String arg[]){
Pila p1=new Pila();
Pila p2=new Pila();
Pila p3=new Pila();
Pila p4=new Pila();
Scanner sc=new Scanner(System.in);
int n1,numero;
System.out.println("Cuantos datos decea ingresar?" );
n1=sc.nextInt();
System.out.println("Ingrese los datos:" );
for(int i=0;i<n1;i++)
{numero=sc.nextInt();
p1.push(numero);
}
int cont=0,aux1=0;
while(!p1.isEmpty()){
int aux=p1.pop();
p4.push(aux);
aux1=aux1+aux;
cont++;
}
int promedio=aux1/cont;
while(!p4.isEmpty()){ int aux=p4.pop();
if(aux>promedio){p2.push(aux); }
if(aux<promedio){p3.push(aux); }
}
System.out.println("Datos mayores al promedio"+" "+promedio+" "+"son:" );
while(!p2.isEmpty()){ System.out.println(p2.pop());
}
System.out.println("Datos menores al promedio"+" "+promedio+" "+"son:" );
while(!p3.isEmpty()){System.out.println(p3.pop()); }
}
}
Las demas Clases :
class Nodo{
int info;
Nodo enlace;
public Nodo(int a){
info=a;
enlace=null;
}
}
La clase Pila :
class Pila{
Nodo first,top;
boolean isEmpty(){
if(first==null)
return true;
else
return false;
}
void push(int a){
if(isEmpty())
{first=new Nodo(a);
top=first;
}
else{
Nodo temp=new Nodo(a);
top.enlace=temp;
top=temp;
}
}
int pop(){
int aux;
if(isEmpty())
return -1;
else
{
if(first.enlace==null){
aux=first.info;
first=null;
top=null;
}
else{ Nodo temp=first;
while(temp.enlace!=top){
temp=temp.enlace; }
aux=top.info;
temp.enlace=null;
top=temp;
}
}
return aux;
}
int peek(){
if(isEmpty())
return -1;
else
return top.info;
}
}
Atte ; Willians Melchor Huarachi
Si no me creen ya publico fotos XD