<div>Would this be O(n^2) to remove all nils?<br> </div>
<div>In any case, if this is a conveyor belt, then you should almost certainly be using a linke data structure, and iterate over the structure to delete the unwanted links. <br> </div>
<div><span class="gmail_quote">On 9/18/08, <b class="gmail_sendername">Bert Freudenberg</b> <<a href="mailto:bert@freudenbergs.de">bert@freudenbergs.de</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><br>Am 18.09.2008 um 10:06 schrieb Ian J Cottee:<span class="q"><br><br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hello all<br><br>I've got an OrderedCollection that is normally a fixed size (let's say<br>10 elements). Each element in the collection is another an object or<br>
nil. So for example, at a point in time it might look like<br><br> [nil, nil, Object, nil, Object, Object, nil, nil, Object, nil]<br><br>What I want is to be able to resize the collection. Making it bigger<br>is no problem for me, I can just add nils to the end of the<br>
collection. Making it smaller is involving a little bit of pain. I can<br>see ways of doing it but theyr'e not elegant and I'm sure there are<br>cleaner ways of doing it. If I made the above queue smaller I'd<br>
basically remove the nils starting from the beginning. So a resize to<br>size 7 would give me<br><br>[ Object, Object, Object, nil, nil, Object, nil]<br><br>i.e. the first three nils have been removed.<br><br>Does anybody have any comments on appropriate code to handle this? If<br>
not, I'll go with the ugly stuff but it would be nice to know the<br>correct SmallTalk way.<br><br>Many thanks for any suggestions.<br></blockquote><br><br></span>I guess it doesn't get much more elegant and efficient than<br>
<br> start := coll findFirst: [:each | each ~~ nil].<br> coll removeFirst: start-1.<br><br>... unless you add a specific method to OC.<br><span class="sg"><br>- Bert -</span>
<div><span class="e" id="q_11c74a2449723270_4"><br><br><br>_______________________________________________<br>Beginners mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:Beginners@lists.squeakfoundation.org" target="_blank">Beginners@lists.squeakfoundation.org</a><br>
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://lists.squeakfoundation.org/mailman/listinfo/beginners" target="_blank">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a><br></span></div>
</blockquote></div><br>