I have written a few linked list subroutines (See below)
I want to move these subroutines in to a package
Queue::LList

1) Queue must be a subdirectory containing file LList.pm

2) Need create and test package using the test calls(see
code below)

3) Need to use the same variable names and package names as
in the code below 

Thanks in advance

Cheers
Naomi


CODING
-----------------------------------------------------------
#create list (1)
#----------------------------
sub createllist   {
       my $val  = shift;
       my node = shift;

if (  !defined ( $node ) ) {
   die 'I need a scalar reference';}

if ( defined ( $$node ) ) {
  die 'You already have a node! ':}
$$node = {
    'data' => $val,
    'next' => undef,
};
}
# References V Example Linked List (2)
#--------------------------------------------------------------
sub addnode {
      my $val = shift;
      my $list  = shift;
      if ( !defined ($list ) ) {
           die 'I need a scalar reference';}
      if ! defined ($$list )) {
         print "Creating list \n";
         createllist ( $val, $list);
      return;
      }
      if ( defined ($$list -> {'next'} )) {
           $list = $$list ->    {'next'};
      }else {
          $$list -> {'next'} = {
                   'data' => $val,
                   'next' => undef,
          };
          return;
       }
       while ( defined ($list -> {'next'} )) {
             $list = $list -> {'next'};
       }
       $list -> {'next'} = {
           'data' => $val,
           'next'  => undef,
      };
}          

# To print the values to be used (3)
#-------------------------------------------------------

sub printllist {
       my $list = shift;

      while ( defined ( $list ) ) {
      print $list -> {'data'}, "\n";
      $list -> {'next'};
      }
}

#for debugging, use the  Data::Dumper module:
use Data::Dumper;
my $llist;
addnode (1,\$llist );

print "dump:";
print Dumper ($llist);
addnode (2,\$llist );
addnode (3,\$llist );
addnode (4,\$llist );
printlist ( $llist );

print "dump:";
print Dumper ($llist);


#(4)
#some subroutine that remove a centre link , from linklist.
This link is #specified by value that are different)
#-------------------------------------------------------------------------------------------------------------
 
==
Brought to you by Ananzi Shopping for specials, competitions and free goodies!
[http://www.ananzishopping.co.za]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to