#!/usr/local/bin/perl -w

use strict ;

package List ;
use Node ;


sub new {

   my $me = {} ;
   $me->{'root'} = new Node ;
   $me->{'total'} = 0 ;
   $me->{'length'} = 0 ;
   bless $me ;
   return $me ;

}

sub print {

   my $self = shift ;
   my $noderef = $self->{'root'}->getNext ;
   while ( $noderef ) {
      print "Count: ", $noderef->getCount, 
            " Word: ", $noderef->getWord,
            "\n" ;
      $noderef = $noderef->getNext ;
   }

}

sub addWord {

   my ($self, @words ) = @_ ;
   my $word ;
   foreach $word (@words) {
      my $n = new Node ;
      $n->setWord($word) ;
      $n->setCount(1) ;
      $n->setNext( $self->{'root'}->getNext ) ;
      $self->{'root'}->setNext( $n ) ;
      $self->{'count'}++ ;
      $self->{'length'} ++ ;
   }

}

sub findWord {
   my ( $self, $word ) = @_ ;
   my $nt = $self->{'root'} ;
   my $n = $nt->getNext ;
   while ( $n && ($n->getWord ne $word ) ) {
      $nt = $n ;
      $n = $n->getNext ;
   }
   ($n) ? $nt : 0 ;
}

sub incrementCount {

   my ($self, $foundling ) = @_ ;
   my $trueFoundling = $foundling->getNext ;
   $trueFoundling->setCount( ($trueFoundling->getCount) +1 );
   $self->{'total'} ++ ;

}



1; # happy package
