Monday, October 8, 2007
The Linked List Maker method
The methods missing from yesterday's post...
public class IntList {
// Names of simple Containers
public int head;
public IntList tail;
// Constructor function
/** List Cell containing (HEAD, TAIL). */
public IntList (int head, IntList tail) {
this.head = head; //Scheme car
this.tail = tail; //Scheme cdr
}
/* Converts an Array of Integers into a Linked List with
* the same elements.
* @param: an Array of integers with > 1 elements
*/
static IntList makeList (int a []) {
IntList X, Z;
X = new IntList (a[0], null);
int i;
for (i = 1, Z = X; i < z =" Z.tail){" tail =" new" i =" 0;" x =" new" z =" X;" z =" makelistrhelper"> a.length -1 ){
return Z;
} else {
Z.tail = new IntList (a[i], null);
return makelistrhelper (Z.tail, a, ++i);
}
}
static int countList (IntList Z) {
int countL = 0;
countL = countListH (Z, countL);
return countL;
}
static int countListH (IntList Z, int countL){
if (Z == null)
return countL;
else {
return countListH (Z.tail, ++countL);
}
}
static void printList (IntList Z) {
int i = 0;
IntList M;
for (M = Z; M != null; M = M.tail ) {
System.out.println("Head" + "-" + i +" ---- " + M.head);
i++;
}
}
}
Subscribe to:
Post Comments (Atom)
Just some daily notes ...
Things I'm into now...
Blog Archive
-
▼
2007
(29)
-
▼
October
(15)
- Deconstructing a Scheme recursive function and imp...
- Anasi Boys
- Iterator for Collection and Nested Class
- The Uninvited!
- Inheritence and PolyMorphIsm
- Iterator Example
- Java Library ArrayList
- Inserting into an array non-destructively
- Singly linked list operations...
- PascalTriangles once more!
- Sieve of Erotosthenes
- Linked List Constructor Functionality Testing
- The Linked List Maker method
- Simple Linked List operations
- Old blogs before Day 0.
-
▼
October
(15)
No comments:
Post a Comment