Circular stack

Circular stack

Anonymous
Not applicable
586 Views
6 Replies
Message 1 of 7

Circular stack

Anonymous
Not applicable
Hi, I know this is not a ARX question, but i need it for an ARX app and after hunting the web for days I thought maybe... Can anybody point me to a implementation/article etc. of a circular stack? I mean a fixed size stack of n elements, where the nth+1 pushed element replaces the 1st. TIA, alex
0 Likes
587 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Hi alex,

If you are asking for circlular queue, then you'll be quite easy to find it, because it is "tandard" and is described in many data structure textboks. But circlular stack is usually absent in those books, due to the limited applications. Im pretty curious what requirement makes you decided to use a fixed size stack, instead of a normal stack which can grow as big as you wish. But anyways I had better not to add your burdon at this moment.
My suggestion is , you can implement circular stack by using the template AcArray, and it shoud be quite easy for you to implement, IMHO.
0 Likes
Message 3 of 7

Anonymous
Not applicable
Hi Horace, I decided for a fixed size stack rather than a normal one because - in my app - its size would be user-dependent and could get out of control.(think of MRU implementations - they do use a fixed size 'stack'). To the subject matter, I found a zillion of queues (circular and otherwise) but no stacks. I'm looking for a standard implementation, as I wouldn't want to (re)invent the wheel, at least not now. thanks, alex
0 Likes
Message 4 of 7

Anonymous
Not applicable
alex wrote: > Can anybody point me to a implementation/article etc. > of a circular stack? > I mean a fixed size stack of n elements, where the nth+1 > pushed element replaces the 1st. Given a stack of 4 elements, are you wanting the 5th element to be at the top of the stack or the bottom? -- There are 10 kinds of people: those who understand binary and those who don't.
0 Likes
Message 5 of 7

Anonymous
Not applicable
At the top (otherwise it would be a queue).. I mean: For a 4 elements stack, here are a few ops:(stack top in bold) stack pos 0 1 2 3 -------------------------------------------- push a a push b a b push c a b c push d a b c d push e e b c d //pointer wraps around push f e f c d pop gets f e c d pop gets e c d pop gets d c pop gets c pop gets NULL/stack empty error alex
0 Likes
Message 6 of 7

Anonymous
Not applicable
This probably doesn't help, but usually I find it quicker to reinvent the wheel than to research something I can't find. Horace is correct, it would be simple to derive from AcArray and make it into what you need. "alex" wrote in message news:411db02d_3@newsprd01... > Hi, > > I know this is not a ARX question, but i need it for an ARX app and > after hunting the web for days I thought maybe... > > Can anybody point me to a implementation/article etc. > of a circular stack? > I mean a fixed size stack of n elements, where the nth+1 > pushed element replaces the 1st. > > TIA, > > alex > >
0 Likes
Message 7 of 7

Anonymous
Not applicable
I got it now: derived from AcArray and also 'reinvented the wheel'. Your ideas were valuable. Many thanks, alex
0 Likes