Difference between revisions of "CSC212 Lab 6 Solutions 2014"

From dftwiki3
Jump to: navigation, search
Line 8: Line 8:
 
<source lang="java">
 
<source lang="java">
  
class IntSLLNode2 {
+
class IntSLLNode {
 
public int info;
 
public int info;
public IntSLLNode2 next;
+
public IntSLLNode next;
public IntSLLNode2( int el ) { this( el, null ); }
+
public IntSLLNode( int el ) { this( el, null ); }
public IntSLLNode2( int el, IntSLLNode2 n ) { info = el; next = n; }
+
public IntSLLNode( int el, IntSLLNode n ) { info = el; next = n; }
 
}
 
}
  
  
 
public class Lab6_2 {
 
public class Lab6_2 {
IntSLLNode2 head, tail;
+
IntSLLNode head, tail;
 
int length;
 
int length;
 
 
Line 30: Line 30:
 
 
 
public void addToHead( int el ) {
 
public void addToHead( int el ) {
head = new IntSLLNode2( el, head );
+
head = new IntSLLNode( el, head );
 
if ( tail==null )  
 
if ( tail==null )  
 
tail = head;
 
tail = head;
Line 40: Line 40:
 
addToHead( el );
 
addToHead( el );
 
else {
 
else {
tail.next = new IntSLLNode2( el );
+
tail.next = new IntSLLNode( el );
 
tail = tail.next;
 
tail = tail.next;
 
}
 
}
Line 47: Line 47:
 
 
 
public void printAll() {
 
public void printAll() {
for ( IntSLLNode2 it=head; it != null; it = it.next  )  
+
for ( IntSLLNode it=head; it != null; it = it.next  )  
 
System.out.print( it.info + " " );
 
System.out.print( it.info + " " );
 
System.out.println( );
 
System.out.println( );

Revision as of 12:05, 1 October 2014

--D. Thiebaut (talk) 13:04, 1 October 2014 (EDT)




...