in reply to (jeffa) Re: joining and sorting arrays
in thread joining and sorting arrays

the problem is that the new input isn't have to be consecutive to the last (in each iteration the user enters a series of numbers - theses should be consecutive), only the joined array should be consecutive

Hotshot
  • Comment on Re: (jeffa) Re: joining and sorting arrays

Replies are listed 'Best First'.
Re: Re: (jeffa) Re: joining and sorting arrays
by fuzzysteve (Beadle) on Dec 04, 2001 at 23:47 UTC
    The idea is still valid though. it just doesn't replace checks after the data entry.
    break up the task
    Ensure each new array is internally consecutive
    easiest to do at data entry, when you don't have to think about all the other arrays
    all the arrays together should hold 0 to #, and no number apears more than once.
    after data entry. join the arrays, and sort it, as you are doing now

    It adds a step, but doen't add much complexity.

    This is assuming that the data is entered within 2 loops, that you can have the the check reset. something like:
    my %list; for my $outer=(1..5){ my $last=0; for my $inner=(0..9){ my $number=<STDIN>; unless ($last==0) { unless ($number==$last+1){ die("bad input"); } $list{$outer}[$inner]=$number; } }
    Course its very rough code (and probably won't work without tweaking {or a total rewrite}) the principal is there.