V
viking2.0
Can someone give a general idea about how to Implement the class
defined in this Javadoc-generated documentation.
--------------------------------------------------------------------------------
Class List
java.lang.Object
List
--------------------------------------------------------------------------------
public class List
extends java.lang.Object
Class List implements linked lists as used in the language LISP. Each
list is either an "atom" (containing a string) or else it has a "head"
and "tail" that are also lists. To implement this class, use three
private members, List head, List tail, Object atom.
--------------------------------------------------------------------------------
Field Summary
static List NIL
NIL has head = tail = null and atom = "".
Constructor Summary
List()
The default constructor constructs NIL
List(List x)
Creates a one element list containing list x
List(java.lang.String x)
This constructor makes an atom with the specified value
Method Summary
List append(List y)
append(y) is the same as append(this,y).
static List append(List x, List y)
append(x,y) makes the last element of x have tail y.
java.lang.String atomAsString()
atomAsString returns the string representation of the data
stored in an atom.
static List caddr(List x)
caddr(x) = car(cdr(cdr(x))), which is the third element of
list x, if x has a third element.
static List cadr(List x)
cadr(x) = car(cdr(x))
List car()
car with no arguments is a member function that returns
car(this)
static List car(List x)
car(x) returns x.head, so the data member x can be private.
List cdr()
cdr with no arguments is a member function that returns
cdr(this)
static List cdr(List x)
cdr(x) returns x.head, so the data member x can be private.
static List cons(List x, List y)
cons takes two lists x and y, and produces a new list with
head x and tail y.
List copy()
Makes a shallow copy of a list
boolean equals(List x)
equals(x) returns true if x is equal to this, false otherwise
static boolean equals(List x, List y)
equals(x,y) returns true if x is equal to y, false otherwise
java.lang.Boolean isAtom()
isAtom returns true on atoms and false on other lists.
java.lang.Boolean isNIL()
isNIL returns true on NIL and false on other lists.
int length()
Returns the length of a list.
static List list(List x)
Creates a one element list containing list x
static List list(List a, List b)
Creates a two-element list
static boolean member(List x, List y)
member(x,y) returns true if x is a member of list y, false
otherwise
protected static List rev_aux(List x, List y)
append y to the reverse of x.
List reverse()
reverse returns a new list with the elements of x in reverse
order.
java.lang.String toString()
toString converts a list to a string representation such as
(A,(B,C),D,E).
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait,
wait, wait
Field Detail
NIL
public static final List NILNIL has head = tail = null and atom = "".
Constructor Detail
List
public List(java.lang.String x)This constructor makes an atom with the
specified value
--------------------------------------------------------------------------------
List
public List()The default constructor constructs NIL
--------------------------------------------------------------------------------
List
public List(List x)Creates a one element list containing list x
Method Detail
car
public static List car(List x)car(x) returns x.head, so the data member
x can be private. The name is traditional, from LISP. If x is NIL or an
atom, car(x) is NIL.
--------------------------------------------------------------------------------
car
public List car()car with no arguments is a member function that
returns car(this)
--------------------------------------------------------------------------------
cdr
public static List cdr(List x)cdr(x) returns x.head, so the data member
x can be private. The name is traditional, from LISP. If x is NIL or an
atom, cdr(x) is NIL.
--------------------------------------------------------------------------------
cdr
public List cdr()cdr with no arguments is a member function that
returns cdr(this)
--------------------------------------------------------------------------------
cadr
public static List cadr(List x)cadr(x) = car(cdr(x))
--------------------------------------------------------------------------------
caddr
public static List caddr(List x)caddr(x) = car(cdr(cdr(x))), which is
the third element of list x, if x has a third element.
--------------------------------------------------------------------------------
isAtom
public java.lang.Boolean isAtom()isAtom returns true on atoms and false
on other lists. NIL is not considered an atom.
--------------------------------------------------------------------------------
atomAsString
public java.lang.String atomAsString()atomAsString returns the string
representation of the data stored in an atom.
--------------------------------------------------------------------------------
isNIL
public java.lang.Boolean isNIL()isNIL returns true on NIL and false on
other lists.
--------------------------------------------------------------------------------
list
public static List list(List x)Creates a one element list containing
list x
--------------------------------------------------------------------------------
list
public static List list(List a,
List b)Creates a two-element list
--------------------------------------------------------------------------------
cons
public static List cons(List x,
List y)cons takes two lists x and y, and
produces a new list with head x and tail y.
--------------------------------------------------------------------------------
length
public int length()Returns the length of a list. NIL has length zero.
--------------------------------------------------------------------------------
copy
public List copy()Makes a shallow copy of a list
--------------------------------------------------------------------------------
append
public static List append(List x,
List y)append(x,y) makes the last element of
x have tail y. Neither list is copied, and list y is not altered.
Remark: thus appending a list to itself would be a mistake.
--------------------------------------------------------------------------------
append
public List append(List y)append(y) is the same as append(this,y).
--------------------------------------------------------------------------------
equals
public boolean equals(List x)equals(x) returns true if x is equal to
this, false otherwise
--------------------------------------------------------------------------------
equals
public static boolean equals(List x,
List y)equals(x,y) returns true if x is
equal to y, false otherwise
--------------------------------------------------------------------------------
member
public static boolean member(List x,
List y)member(x,y) returns true if x is a
member of list y, false otherwise
--------------------------------------------------------------------------------
reverse
public List reverse()reverse returns a new list with the elements of x
in reverse order. The elements of list x are themselves not copied,
i.e., this is a shallow copy. Hint: to implement reverse, use rev_aux.
--------------------------------------------------------------------------------
rev_aux
protected static List rev_aux(List x,
List y)append y to the reverse of x. Use
this function to implement reverse. This should be private, but I made
it protected so javadoc will process it.
--------------------------------------------------------------------------------
toString
public java.lang.String toString()toString converts a list to a string
representation such as (A,(B,C),D,E). There must be no white space in
the string returned (unless the string data in an atom itself contains
white space).
Overrides:
toString in class java.lang.Object
defined in this Javadoc-generated documentation.
--------------------------------------------------------------------------------
Class List
java.lang.Object
List
--------------------------------------------------------------------------------
public class List
extends java.lang.Object
Class List implements linked lists as used in the language LISP. Each
list is either an "atom" (containing a string) or else it has a "head"
and "tail" that are also lists. To implement this class, use three
private members, List head, List tail, Object atom.
--------------------------------------------------------------------------------
Field Summary
static List NIL
NIL has head = tail = null and atom = "".
Constructor Summary
List()
The default constructor constructs NIL
List(List x)
Creates a one element list containing list x
List(java.lang.String x)
This constructor makes an atom with the specified value
Method Summary
List append(List y)
append(y) is the same as append(this,y).
static List append(List x, List y)
append(x,y) makes the last element of x have tail y.
java.lang.String atomAsString()
atomAsString returns the string representation of the data
stored in an atom.
static List caddr(List x)
caddr(x) = car(cdr(cdr(x))), which is the third element of
list x, if x has a third element.
static List cadr(List x)
cadr(x) = car(cdr(x))
List car()
car with no arguments is a member function that returns
car(this)
static List car(List x)
car(x) returns x.head, so the data member x can be private.
List cdr()
cdr with no arguments is a member function that returns
cdr(this)
static List cdr(List x)
cdr(x) returns x.head, so the data member x can be private.
static List cons(List x, List y)
cons takes two lists x and y, and produces a new list with
head x and tail y.
List copy()
Makes a shallow copy of a list
boolean equals(List x)
equals(x) returns true if x is equal to this, false otherwise
static boolean equals(List x, List y)
equals(x,y) returns true if x is equal to y, false otherwise
java.lang.Boolean isAtom()
isAtom returns true on atoms and false on other lists.
java.lang.Boolean isNIL()
isNIL returns true on NIL and false on other lists.
int length()
Returns the length of a list.
static List list(List x)
Creates a one element list containing list x
static List list(List a, List b)
Creates a two-element list
static boolean member(List x, List y)
member(x,y) returns true if x is a member of list y, false
otherwise
protected static List rev_aux(List x, List y)
append y to the reverse of x.
List reverse()
reverse returns a new list with the elements of x in reverse
order.
java.lang.String toString()
toString converts a list to a string representation such as
(A,(B,C),D,E).
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait,
wait, wait
Field Detail
NIL
public static final List NILNIL has head = tail = null and atom = "".
Constructor Detail
List
public List(java.lang.String x)This constructor makes an atom with the
specified value
--------------------------------------------------------------------------------
List
public List()The default constructor constructs NIL
--------------------------------------------------------------------------------
List
public List(List x)Creates a one element list containing list x
Method Detail
car
public static List car(List x)car(x) returns x.head, so the data member
x can be private. The name is traditional, from LISP. If x is NIL or an
atom, car(x) is NIL.
--------------------------------------------------------------------------------
car
public List car()car with no arguments is a member function that
returns car(this)
--------------------------------------------------------------------------------
cdr
public static List cdr(List x)cdr(x) returns x.head, so the data member
x can be private. The name is traditional, from LISP. If x is NIL or an
atom, cdr(x) is NIL.
--------------------------------------------------------------------------------
cdr
public List cdr()cdr with no arguments is a member function that
returns cdr(this)
--------------------------------------------------------------------------------
cadr
public static List cadr(List x)cadr(x) = car(cdr(x))
--------------------------------------------------------------------------------
caddr
public static List caddr(List x)caddr(x) = car(cdr(cdr(x))), which is
the third element of list x, if x has a third element.
--------------------------------------------------------------------------------
isAtom
public java.lang.Boolean isAtom()isAtom returns true on atoms and false
on other lists. NIL is not considered an atom.
--------------------------------------------------------------------------------
atomAsString
public java.lang.String atomAsString()atomAsString returns the string
representation of the data stored in an atom.
--------------------------------------------------------------------------------
isNIL
public java.lang.Boolean isNIL()isNIL returns true on NIL and false on
other lists.
--------------------------------------------------------------------------------
list
public static List list(List x)Creates a one element list containing
list x
--------------------------------------------------------------------------------
list
public static List list(List a,
List b)Creates a two-element list
--------------------------------------------------------------------------------
cons
public static List cons(List x,
List y)cons takes two lists x and y, and
produces a new list with head x and tail y.
--------------------------------------------------------------------------------
length
public int length()Returns the length of a list. NIL has length zero.
--------------------------------------------------------------------------------
copy
public List copy()Makes a shallow copy of a list
--------------------------------------------------------------------------------
append
public static List append(List x,
List y)append(x,y) makes the last element of
x have tail y. Neither list is copied, and list y is not altered.
Remark: thus appending a list to itself would be a mistake.
--------------------------------------------------------------------------------
append
public List append(List y)append(y) is the same as append(this,y).
--------------------------------------------------------------------------------
equals
public boolean equals(List x)equals(x) returns true if x is equal to
this, false otherwise
--------------------------------------------------------------------------------
equals
public static boolean equals(List x,
List y)equals(x,y) returns true if x is
equal to y, false otherwise
--------------------------------------------------------------------------------
member
public static boolean member(List x,
List y)member(x,y) returns true if x is a
member of list y, false otherwise
--------------------------------------------------------------------------------
reverse
public List reverse()reverse returns a new list with the elements of x
in reverse order. The elements of list x are themselves not copied,
i.e., this is a shallow copy. Hint: to implement reverse, use rev_aux.
--------------------------------------------------------------------------------
rev_aux
protected static List rev_aux(List x,
List y)append y to the reverse of x. Use
this function to implement reverse. This should be private, but I made
it protected so javadoc will process it.
--------------------------------------------------------------------------------
toString
public java.lang.String toString()toString converts a list to a string
representation such as (A,(B,C),D,E). There must be no white space in
the string returned (unless the string data in an atom itself contains
white space).
Overrides:
toString in class java.lang.Object