But since you can do operations on both side of it like suggested, for example pushbase popbase and the ordinary push and pop. It would not follow the LIFO principle, at least it should be signified in some way as a special case of a stack, no?
But since you can do operations on both side of it like suggested, for example pushbase popbase and the ordinary push and pop. It would not follow the LIFO principle, at least it should be signified in some way as a special case of a stack, no?
Stacks are FILO structs in my way of thinking - Queue's are FIFO, and I don't see a really striking resemblance to either one, here.
One more vote for the for or while loop. Any elegance it may appear to lack compared to something like a circular buffer, is more than made up for by the supreme elegance of it's intuitive simplicity.
Last edited by Adak; 06-07-2010 at 09:58 PM.
Symantec arguments aside, how on earth is the case where there is a 4096 value container and two pointer re-assignments and two value assignments somehow less elegant than 4094 reads and 4096 writes? wow.
Hope is the first step on the road to disappointment.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
Now, I know y'all ain't that dumb. Perhaps I should have said "stackish" and "que-esque". No one is going to write something and go, "Well, I can't add a pop from bottom because that disobeys the laws of FILO" or something.
As mentioned several times already, X would be retrieved via a get/set() to do the dead simple arithmetic from the current first element. If you want the 5 element, that's first_element+5-1.
Haven't you people done any actual programming? Or are you recommending one intentionally stick one's head in the sand whilst coding? Sheesh.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Hey, MK it's cool. When stack came up the first time in the thread I thought of it in the most basic classic form, which is why I objected to the use of it in this application. So any debate about it was just to clarify my point.
Hope is the first step on the road to disappointment.
Well since the OP specified operating on the ends of the container and once you have more than a few items, doing two operations will always be faster than two + any extra operations to rotate the contents. Or as you put it ALWAYS. Heh. Since no operations on the middle of the container were specified, none were considered and any extra operations on the middle for the simple purpose of using a specific type are by definition wasted.
array[ x ] = 5;
Is always going to be faster than:
put( 5, x );
It doesn't matter if it's at the beginning, end, or middle. None of that actually matters though, because none of the implementations suggested, by anyone, actually do what they asked to do:
Shift an array, and zero fill the items that were shifted away.
Furthermore, the OP hasn't responded at all to this thread, so the speculation as to "only the ends are accessed" isn't accurate at all. They didn't say anything about only accessing end members.
Quzah.
Last edited by quzah; 06-08-2010 at 07:24 PM.
Hope is the first step on the road to disappointment.
Actually we all screwed the pooch on this one, including you Quzah. Before you hit the reply button in indignation, reread what the OP wrote:
IOW he wanted a second array, not a shifted version of the first one. Stacks and for loops and array access suddenly mean little which is probably why he/she never responded. We were giving him answers to a question he did not ask. Heh.
How would I then use the value to produce a second array that has the depth from 1 to 3cm and then have zeros in the elements after 3cm so that the new array is the same size as he original?