[1769] in java-interest
Re: linked list w/o references or ptrs?
daemon@ATHENA.MIT.EDU (Jason Weiler)
Sat Sep 16 20:41:19 1995
Date: Fri, 15 Sep 1995 11:03:45 -0700
From: weilerj@std.teradyne.com (Jason Weiler)
To: fgreco@lehman.com
Cc: java-interest@java.sun.com
>
> As a response to a question on doing pointer-ish things in Java without
> pointers, someone had posted some code to implement a linked-list.
>
> Anyone have this code handy?
>
> Thanks,
>
> Frank G.
> -
> Note to Sun employees: this is an EXTERNAL mailing list!
> Info: send 'help' to java-interest-request@java.sun.com
>
Frank,
Sure, here's the code I posted before. It's NOT a complete linked list
implemetation, but it'll add links to the list, and display the current
list data - the rest should be just as trivial.
Good luck!
Jason W.
<weilerj@std.teradyne.com>
_____start code_____
import java.lang.*;
class ll {
static private ll head=null;
static private ll point=null;
private int value;
private ll next=null;
protected ll (int newval) {
value = newval;
next = null;
}
public ll () {
value = 0;
next = null;
}
public void addlink(int newval) {
if (head == null) {
head = new ll(newval);
}
else {
point = head;
while (point.next != null)
point = point.next;
point.next = new ll(newval);
}
}
public void show() {
if (head==null) {
System.out.println("Sorry, head is null");
}
else {
point = head;
while (point != null) {
System.out.println(point.value);
point = point.next;
}
}
}
public static void main (String args[]) {
ll top = new ll();
top.addlink(0);
top.addlink(1);
top.addlink(5);
top.addlink(3);
top.show();
top.show();
}
}
_____ end code _____
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com