home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-02-20 | 1.8 KB | 93 lines |
-
- package simula.simset;
-
- import simula.SimulaException;
-
- /**
- * This class implements a double-linked list.
- */
- public class Head extends Linkage
- {
- // --------------------------- VARIABLES --------------------------
- private Link first;
- private Link last;
-
-
- // --------------------------- CONSTRUCTOR ------------------------
- /**
- * Initialize an empty list.
- */
- public Head() {
- first = null;
- last = null;
- }
- /**
- * Returns the number of elements of the list.
- * @return the number of elements of the list.
- */
- public int cardinal() {
- int count = 0;
- Link current;
-
- if (this.empty()) {
- return 0;
- } else {
- current = first;
-
- while (current != null) {
- count++;
- current = (Link) current.suc();
- }
-
- return count;
- }
- }
- /**
- * Clears the list.
- */
- public void clear() {
- first = null;
- last = null;
- pred = null;
- suc = null;
- }
- /**
- * Returns <code>True</code> if the list is empty, <code>False</code>
- * otherwise
- * @return True if the list is empty.
- */
- public boolean empty() {
- return (first == null && last == null);
- }
- // --------------------------- METHODS ------------------------
- /**
- * Returns the first element of the list.
- * @return the first element of the list.
- */
- public Link first() {
- return first;
- }
- /**
- * Sets the first element of the list.
- * @param _first the new element to be first.
- */
- protected void first(Link _first) {
- first = _first;
- suc = (Linkage) _first;
- }
- /**
- * Returns the last element of the list.
- * @return the last element of the list.
- */
- public Link last() {
- return last;
- }
- /**
- * Sets the last element of the list.
- * @param _last the new element to be last.
- */
- protected void last(Link _last) {
- last = _last;
- pred = (Linkage) _last;
- }
- } // end of class Head