AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Liste in Java

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java (Italian)
View previous topic :: View next topic  
Author Message
Bracco Baldo
Guest





PostPosted: Sat Nov 08, 2003 9:21 pm    Post subject: Liste in Java Reply with quote



Ho iniziato a studiare Java da poco e forse la mia domanda e' banale.
La domanda e':
dato che in Java non esistono puntatori, come e' possibile implementare
strutture dati dinamiche come per esempio le liste?



Back to top
[fadeout]
Guest





PostPosted: Sun Nov 09, 2003 12:11 am    Post subject: Re: Liste in Java Reply with quote



"Bracco Baldo" <nqrt (AT) freepass (DOT) it> ha scritto nel messaggio
news:r5drb.2028$i_5.597 (AT) news (DOT) edisontel.com...
Quote:
Ho iniziato a studiare Java da poco e forse la mia domanda e' banale.
La domanda e':
dato che in Java non esistono puntatori, come e' possibile implementare
strutture dati dinamiche come per esempio le liste?

Non esistono puntatori ma in Java tutte le variabili (esclusi i tipi
primitivi) sono *riferimenti* ad oggetti, e quindi in pratica sono come dei
puntatori anche se non proprio come quelli del C (sono invece molto simili
ai riferimenti presenti in C++). Quindi è molto semplice creare una lista
alla C:

class List {
Object value;
List next;
...
}

Puoi trovare un sacco di classi standard già fatte per implementare
strutture dati dinamiche, dai un'occhiata al package java.util




Back to top
ciccio
Guest





PostPosted: Sun Nov 09, 2003 12:18 am    Post subject: Re: Liste in Java Reply with quote




"Bracco Baldo" <nqrt (AT) freepass (DOT) it> ha scritto nel messaggio
news:r5drb.2028$i_5.597 (AT) news (DOT) edisontel.com...
Quote:
Ho iniziato a studiare Java da poco e forse la mia domanda e' banale.
La domanda e':
dato che in Java non esistono puntatori, come e' possibile implementare
strutture dati dinamiche come per esempio le liste?




semplice! ti crei una classe Nodo così:

public class Node {

private Object element;
private Node next;
public Node() {
this(null, null);
}

public Node(Object e, Node n) {
element = e;
next = n;
}

public Object getElement() {
return element;
}

public Node getNext() {
return next;
}

public void setElement(Object newElem) {
element = newElem;
}

public void setNext(Node newNext) {
next = newNext;
}
}



Back to top
Giovanni Martone
Guest





PostPosted: Sun Nov 09, 2003 10:44 pm    Post subject: Re: Liste in Java Reply with quote

In data Sat, 8 Nov 2003 22:21:58 +0100, Bracco Baldo <nqrt (AT) freepass (DOT) it> ha
scritto:

Quote:
Ho iniziato a studiare Java da poco e forse la mia domanda e' banale.
La domanda e':
dato che in Java non esistono puntatori, come e' possibile implementare
strutture dati dinamiche come per esempio le liste?




Forse java.util.LinkedList fa al caso tuo.


G.M.



--
Creato con M2, il rivoluzionario client e-mail di Opera:
http://www.opera.com/m2/

Back to top
Teuzz
Guest





PostPosted: Tue Nov 25, 2003 8:36 pm    Post subject: Re: Liste in Java Reply with quote

class GenericList {
Object theHead;
GenericList theRest;
}

eccoti implementata (seppur ai minimi termini, intendiamoci!) una lista in
java.




Ecco qualcosa di + completo:

class GenericList {

// la parte privata della classe

private Object theHead;
private GenericList theRest;

// parte pubblica

public boolean isEmpty() { //la lista è vuota?
if ( theHead == null && theRest == null)
{
return true;
}
else {
return false;
}
}

public Object head() {
if ( !this.isEmpty() )
{
return theHead; // cosa succede se e` invocato a
// partire da una lista vuota? scoprilo.
}
else {return null;}
}

public GenericList tail() {
if ( !this.isEmpty() )
{
return theRest;
}
else {return null;}
}

public GenericList build(Object a) { //la build inserisce un elemento IN
TESTA alla lista
GenericList risultato = new GenericList();
risultato.theHead = a;
risultato.theRest = this;
return risultato;
}

public GenericList addToEnd (Object a) { //la addtoend inserisce un
elemento in coda alla lista
if (this.isEmpty ()) return build(a);
else return this.tail().addToEnd(a).build(this.head());
}
}



spero di averti aiutato. Ciao!


"Bracco Baldo" <nqrt (AT) freepass (DOT) it> ha scritto nel messaggio
news:r5drb.2028$i_5.597 (AT) news (DOT) edisontel.com...
Quote:
Ho iniziato a studiare Java da poco e forse la mia domanda e' banale.
La domanda e':
dato che in Java non esistono puntatori, come e' possibile implementare
strutture dati dinamiche come per esempio le liste?






Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java (Italian) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.