programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# Set Capacity of array problem

Ranch Hand
Posts: 233
• Number of slices to send:
Optional 'thank-you' note:
Hey Yall, I'm back again. I just can't seem to get this method to work. I really can't figure out a way to decrease the capacity of myArray. I am supposed to change the capacity of this vector to capacity. If the new capacity is smaller than the current size, remove items from the end of this
vector until the size and new capacity are equal.
Here is my main arg calling this method:

And here is my setCapacity method that I have come up with so far:

As you can see I have remarked out a few of my test SOP statements. The loop works and temp stops at capacity 4 and 9 for both int capacity cast in. I am certain that there is something stupid that I am missing or there may be an even better way to accomplish this. I'm open for suggestions.
The output is supposed to look like this:
v[1] = < 2, 3, 4, 5 > (cap: 4)
v[2] = < 3, 2, 1, 0, 1, 2, 3 > (cap: 9)
but it still looks like this:
v[1] = < 2, 3, 4, 5, 6, 7 > (cap: 16)
v[2] = < null, 2, 1, 0, 1, 2, 3 > (cap: 10)

Thanks in advance, and thanks for ALL of your help with everything.
Steve

Gabriel White
Ranch Hand
Posts: 233
• Number of slices to send:
Optional 'thank-you' note:
Well, I have changed my code for this quite a bit. I now have a different output. But now my conditions have switched. My capacity lists correctly but my array is full of null's and 1 number.
My output should look like this:
v[1] = < 2, 3, 4, 5 > (cap: 4)
v[2] = < 3, 2, 1, 0, 1, 2, 3 > (cap: 9)
now it looks like this:
v[1] = < 2, null, null > (cap: 4)
v[2] = < 3, null, null > (cap: 9)
Here is my code:

I could really use the help on this one.

Gabriel White
Ranch Hand
Posts: 233
• Number of slices to send:
Optional 'thank-you' note:
any help would be great.
Thanks again.

Ranch Hand
Posts: 156
• Number of slices to send:
Optional 'thank-you' note:
Have you considered using a for loop that counts downwards, e.g.
for (int i=n-1; i>=0; i--)

Gabriel White
Ranch Hand
Posts: 233
• Number of slices to send:
Optional 'thank-you' note:
Yes, that doesn't work. I think I found the problem.
Thanks anyway
Steve

Gabriel White
Ranch Hand
Posts: 233
• Number of slices to send:
Optional 'thank-you' note:
nope, didn't find it. Still need some assistance.
Thanks

Gabriel White
Ranch Hand
Posts: 233
• Number of slices to send:
Optional 'thank-you' note:
Ok, I got it to work....But
I have null's in my output
Here is what my output looks like now:
v[1] = < 2, 3, 4, 5 > (cap: 4)
v[2] = < 3, 2, 1, 0, 1, 2, 3, null, null > (cap: 9)
I would like to get thoes null's out but I have no clue, I'm stretched on this one.

[ January 30, 2004: Message edited by: Steve Wysocki ]

Loren Rosen
Ranch Hand
Posts: 156
• Number of slices to send:
Optional 'thank-you' note:
What does v[2] look like before you started?

 Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters?