RE: Need someone very familiar with arrays



"Les" wrote:

I was wondering if someone can offer me a clever way of doing the following.
Lets say I have an array like the following:

A(1) = 3
A(2) = 5
A(3) = 0
A(4) = 6
A(5) = 9
A(6) = 10
A(7) = 0
A(8) = 14
A(9) = 0
.
.
A(n)

I need a very efficient method to turn the above array into the following:

A(1) = 3
A(2) = 5
A(3) = 6
A(4) = 9
A(5) = 10
A(6) = 14
.
.
A(n)

Notice the array has been rewritten but excludes the ones that equalled
zero. Now I can do this by checking each array and rewritting it but I am
hoping that there exists a trick of the trade to do it fast. I am also
willing to consider dumping tihs array to another array if that helps you
folks out in a solution. Im hoping that there is a way to just work with the
array as a whole but lets see what you people can think of.

Keeping my fingers crossed,

Les

Hi Les,

First of all I want to apologize on behalf for everyone that has responded
and made what should be very simple into something that became a complicated
headache... (a Linked List for THIS, gimme a break!)

So, it's clear you are not sorting, just shuffling down to get rid of the 0
value gaps... you should keep the original array as you preferred. The ONLY
question is whether you want to redimension your array bounds or keep all the
zeros at the end?

It looks to me like Robert Morley already solved this in his first post,
except I would have done it slightly different because if your first value
happens to be a zero it would be missed :P (Sorry Rob)
.



Relevant Pages

  • Re: non repeating random numbers
    ... numeric array, all of its elements are set to zero. ... However, as I said in the beginning, this method of assigning ... (making it an efficient method to use). ...
    (microsoft.public.vb.general.discussion)
  • Re: Arrays of zero length
    ... The minor strangeness is that when you allocate an array to zero size, ... saying something like that allocating an array makes it undefined ... In f77, zero-size was disallowed, ...
    (comp.lang.fortran)
  • Re: should every thing be zero indexed?
    ... Other families of languages count from 1. ... its number is zero: I always start counting at zero". ... > as a fundamental concept in both the definition of array indices and ... > for I in foo'range loop ...
    (comp.programming)
  • Re: Subset Sum problem (w/ limited scope)
    ... The "Subset Sum" problem (stated various ways depending on what you ... a subset of those integers that sums up to zero. ... Are there going to be duplicate values in your original array? ...
    (comp.lang.fortran)
  • Re: addEvent - The late entry :)
    ... take any number of arguments and append them to an array. ... argument, which is fine on everything but Firefox, where it makes the ... 20 arguments Windows Safari 3 executes that expression in 48% of the ... and at zero arguments 47%. ...
    (comp.lang.javascript)

Loading