/
Forside
/
Teknologi
/
Udvikling
/
Java
/
Spørgsmål
Login
Brugernavn
*
Kodeord
*
Husk mig
Brugerservice
Kom godt i gang
Bliv medlem
Seneste indlæg
Stil et spørgsmål
Skriv et tip
Pointsystemet
Kontakt Kandu.dk
Emnevisning
Kategorier
Alfabetisk
Karriere
Interesser
Teknologi
Reklame
Top 10 brugere
Java
#
Navn
Point
1
molokyle
3688
2
Klaudi
855
3
strarup
740
4
Forvirret
660
5
gøgeungen
500
6
Teil
373
7
Stouenberg
360
8
vnc
360
9
pmbruun
341
10
mccracken
320
intStack
17-03-05 12:25
: Abdis
17-03-05 14:26
: molokyle
31-03-05 10:31
: Abdis
intStack
Fra :
Abdis
Vist : 999 gange
70 point
Dato :
17-03-05 11:44
who can help me to make intstack with the four operation
tak
Accepteret svar
Fra :
molokyle
Modtaget 70 point
Dato :
17-03-05 14:26
Først en Node pladsholder :
Kode
/**
* A Node is an object that holds an int and a link
* to the next Node. It can be used to build linked
* lists of ints.
*/
public class Node {
private int data; // Each node has an int...
private Node link; // ...and a link to the next Node
/**
* Node constructor.
* @param theData the int to store in this Node
* @param theLink a link to the next Node
*/
public Node(int theData, Node theLink) {
data = theData;
link = theLink;
}
/**
* Accessor for the int data stored in this Node.
* @return our int item
*/
public int getData() {
return data;
}
/**
* Accessor for the link to the next Node.
* @return the next Node
*/
public Node getLink() {
return link;
}
}
..og så intStack klassen der gør brug af Node :
Kode
/**
* An IntStack is an object that holds a stack of ints.
*/
public class IntStack {
private Node top = null; // The top Node in the stack
/**
* Test whether this stack has more elements.
* @return true if this stack is not empty
*/
public boolean hasMore() {
return (top != null);
}
/**
* Pop the top int from this stack and return it.
* If the stack is empty we return 0 and leave the
* stack empty.
* @return the popped int or 0 if the stack is empty
*/
public int pop() {
Node n = top;
if (n == null) return 0;
top = n.getLink();
return n.getData();
}
/**
* Push an int on top of this stack.
* @param data the String to add
*/
public void push(int data) {
top = new Node(data,top);
}
}
..source code fra :
http://www.webber-labs.com/mpl/source%20code/
</MOLOKYLE>
Godkendelse af svar
Fra :
Abdis
Dato :
31-03-05 10:31
Tak for svaret molokyle.
Du har følgende muligheder
Eftersom du ikke er logget ind i systemet, kan du ikke skrive et indlæg til dette spørgsmål.
Hvis du ikke allerede er registreret, kan du gratis blive medlem, ved at trykke på "Bliv medlem" ude i menuen.
Søg
Alle emner
Teknologi
Udvikling
Java
Indstillinger
Spørgsmål
Tips
Usenet
Reklame
Statistik
Spørgsmål :
177817
Tips :
31980
Nyheder :
719565
Indlæg :
6410968
Brugere :
218912
Månedens bedste
Årets bedste
Sidste års bedste
Copyright © 2000-2026 kandu.dk. Alle rettigheder forbeholdes.