Java - ayudenme porfavor!!!

 
Vista:

ayudenme porfavor!!!

Publicado por Mariel (2 intervenciones) el 04/12/2006 22:30:14
Me dieron un trabajo sobre la implementacion de estructuras de datos y tengo q realizar un programa que tenga interfaz gráfica pero q utilice pilas, colas, listas o arboles si alguien posee un programa con estas caracterizticas porfavor envieme la respuesta a mi correo Muchas Gracias!!! (solo debe tener una sola estructura es decir solo pilas, solo colas, etc)
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:ayudenme porfavor!!!

Publicado por luis (88 intervenciones) el 05/12/2006 00:38:03
Esque depende tambien de que quieres que haga tu programa tambien no lo comentes tan en general bueno yo tego un ejemplo que hice utilizando LinkedList (es una aplicacion Que interfaz grafica necesitas?)
que prueba algunos de los metodos que implementa esta clase a ver si te sirve:


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Collection;
import java.util.ListIterator;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.LinkedList;
import java.util.Date;
import java.util.NoSuchElementException;
import java.text.SimpleDateFormat;

public class ReadListCpy
{
/*_____________________________________________________________________________
*
* MAIN
*___________________________________________________________________________*/

public static void main ( String argv [ ] )throws IOException
{
//---creating Object varibles and primitive ones---

BufferedReader in = null;
String s = null,
menu = null,
line = null;
Object remove = null,
change = null;
LinkedList list = null;
Calendar calendar = null;
Date date = null;
SimpleDateFormat localFormat = null;
int insert = 0,
i = 0,
x = 0;
ListIterator ite = null;

//--- instances of the class ---
list = new LinkedList ( );
in = new BufferedReader (new InputStreamReader ( System.in ));
menu = ( "________________________________________\n" +
"________________________________________\n" +
"__________________MENU__________________\n" +
"________________________________________\n" +
"__ 0 ) Get the size of the list __\n" +
"__ 1 ) Add at the begining of the list__\n" +
"__ 2 ) Add in a specific position __\n" +
"__ 3 ) Add at the end of the list __\n" +
"__ 4 ) Get the first element __\n" +
"__ 5 ) Get the last element __\n" +
"__ 6 ) Get at specific index __\n" +
"__ 7 ) Erase the first element __\n" +
"__ 8 ) Erase the last element __\n" +
"__ 9 ) Erase at a specific index __\n" +
"__ 10 ) Replace the element by other __\n" +
"__ 11 ) Print the elements of the list__\n" +
"__ 12 ) Clears all the list __\n" +
"__ 13 ) Exit __\n" +
"________________________________________\n" +
"________________________________________\n" +
"________________________________________\n" );

System.out.println ( menu );
System.out.println ("option?");
//--- to exit the program ---


while (insert != 13 )
{
try
{
ite = list.listIterator( );

insert = Integer.parseInt (in.readLine( ));

calendar = new GregorianCalendar ( );

date = calendar.getTime ( );

localFormat = new SimpleDateFormat ( "dd/MMM/yyyy" );

s = localFormat.format (new Date( ));

//--- validate options ---
if (insert > 13 || insert < 0)
{
System.err.println ("\n Invalid option!!!!");
System.out.println ( menu );
System.out.println ("option?");
}



//--- size of the list ---
if (insert == 0 )
{
System.out.println ("number of items added at the list: "+
list.size( ));
System.out.println ( menu );
System.out.println ("option?");
}


//--- adding elements ---
if (insert == 1 )
{

list.addFirst ( s + " " +
calendar.get(calendar.HOUR_OF_DAY) + ":" +
calendar.get(calendar.MINUTE)+ ":" +
calendar.get(calendar.SECOND)+ ":" +
calendar.get(calendar.MILLISECOND));
System.out.println ( menu );
System.out.println ("option?");
}
if (insert == 2)
{

try
{

System.out.println("Set position!!!! ");
x = Integer.parseInt (in.readLine( ));
list.add (x, s+" "+calendar.get(calendar.HOUR_OF_DAY)+":"+
calendar.get(calendar.MINUTE)+":"+
calendar.get(calendar.SECOND)+":"+
calendar.get(calendar.MILLISECOND));
System.out.println ( menu );
System.out.println ("option?");
}
catch (IndexOutOfBoundsException e)
{
System.err.println ("Index out of range!!!! "+
e.toString());
System.out.println ( menu );
System.out.println ("option?");
}
} //---Add in a specific position ------

if (insert == 3 )
{
list.addLast ( s+" "+calendar.get(calendar.HOUR_OF_DAY)+":"+
calendar.get(calendar.MINUTE)+":"+
calendar.get(calendar.SECOND)+":"+
calendar.get(calendar.MILLISECOND));
System.out.println ( menu );
System.out.println ("option?");
}

//--- get the values ---
if ( insert == 4 )
{
try
{
System.out.println ( list.getFirst ( ));
System.out.println ( menu );
System.out.println ("option?");
}
catch (NoSuchElementException e)
{
System.err.println ("No elements added yet!!!! "+e.toString( ));
System.out.println ( menu );
System.out.println ("option?");
}
}
if ( insert == 5 )
{
try
{
System.out.println ( list.getLast ( ));
System.out.println ( menu );
System.out.println ("option?");
}
catch (NoSuchElementException e)
{
System.err.println ("No elements added yet!!!! "+
e.toString ( ));
System.out.println ( menu );
System.out.println ("option?");
}
}
if ( insert == 6 )
{
try
{
System.out.println("Set index to retrieve!!!!");
x = Integer.parseInt (in.readLine( ));
System.out.println ( list.get ( x ));
System.out.println ( menu );
System.out.println ("option?");
}
catch (IndexOutOfBoundsException e)
{
System.err.println ("There's no element at the " +
"specified index!!!! " +
e.toString( ));
System.out.println ( menu );
System.out.println ("option?");
}
}

//--- erasing ---
if (insert == 7 )
{
try
{

remove = list.removeFirst ( );
System.out.println ( menu );
System.out.println ("option?");
}
catch (NoSuchElementException e)

{
System.out.println("There's no elements in the list!!!! "+
e.toString( ));
System.out.println ( menu );
System.out.println ("option?");
}
}
if ( insert == 8 )
{

try
{
remove = list.removeLast ( );
System.out.println ( menu );
System.out.println ("option?");
}

catch (NoSuchElementException e)
{
System.err.println("There's no elements in the list!!!! "+
e.toString( ));
System.out.println ( menu );
System.out.println ("option?");
}

}
if ( insert == 9 )
{
try
{
System.out.println("Set index to erase!!!!");
x = Integer.parseInt(in.readLine( ));
remove = list.remove( x );
System.out.println ( menu );
System.out.println ("option?");
}
catch (IndexOutOfBoundsException e)
{
System.err.println("Couldn't find that index!!!! "+
e.toString( ));
System.out.println ( menu );
System.out.println ("option?");
}
}

//--- changing ---
if (insert == 10)
{
try
{
System.out.println("Set index to replace!!!!");
x = Integer.parseInt(in.readLine( ));
change = list.set (x, s+" "+calendar.get(calendar.HOUR_OF_DAY)+":"+
calendar.get(calendar.MINUTE)+":"+
calendar.get(calendar.SECOND)+":"+
calendar.get(calendar.MILLISECOND )) ;
System.out.println ( menu );
System.out.println ("option?");
}
catch (IndexOutOfBoundsException e)
{
System.err.println ("Index is empty!!!! "+e.toString( ));
System.out.println ( menu );
System.out.println ("option?");
}
}


//--- print the list ---
if (insert == 11 )
{
if(list.size( ) == 0)
{
System.out.println("the list is empty!!!!");

}
i = 0;
while (ite.hasNext ( ))
{
line = (String) ite.next ( );
System.out.println ("Position: " + i + " " +
"index: "+" "+
list.indexOf( line ) + " "+line);
i ++;
}
System.out.println ( menu );
System.out.println("option?");
}


if (insert == 12)
{
if(list.size( ) == 0)
{
System.out.println("the list is empty!!!!");

}

list.clear( );

System.out.println( menu );
System.out.println("option?");
}
}
catch (NumberFormatException e)
{
System.err.println ("No strings!!!! "+ e.toString( ));
System.out.println ( menu );
System.out.println ("option?");
}

}

}/*________________________END OF MAIN METHOD______________________________*/
}/*_________________________END OF StdInput CLASS____________________________*/
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar