Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

Stack question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SP - 19 Nov 2006 10:12 GMT
Hi,

I've a Stack. Now I would use this to mantain a LIFO objects chain.
My problem is that I want to limit the Stack dimension. If the Stack is
full and I want to add a object, I eant to remove the bottom element
and put the new element in the top.
It is possbible with this Objet? Or I must make my struct?
Michael C - 19 Nov 2006 12:36 GMT
> Hi,
>
[quoted text clipped - 3 lines]
> and put the new element in the top.
> It is possbible with this Objet? Or I must make my struct?

That description is not a stack, you probably should just use an arraylist
and possibly wrap it in your own class.
PS - 19 Nov 2006 19:31 GMT
> Hi,
>
> I've a Stack. Now I would use this to mantain a LIFO objects chain.
> My problem is that I want to limit the Stack dimension. If the Stack is
> full and I want to add a object, I eant to remove the bottom element
> and put the new element in the top.

First, you have your terminology wrong. Last In, First Out would mean that
once you have reached the limit you would just stop adding new items. That
is because you are saying that the last element added should be the first
element removed, so why bother adding it at all. You are wanting a First In
First Out collection which is a Queue. You dequeue when the count exceeds
your limit.

myQueue.Enqueue(myObject);
if(myQueue.Count > 10)
   myQueue.Dequeue();

PS

> It is possbible with this Objet? Or I must make my struct?
SP - 23 Nov 2006 13:36 GMT
Why I'm wrong?
LAST IN FIRST OUT is using the structure, that is, when I need to read
the datastructure I Pop the Stack. When I want to insert a element i
need to Push in the Stack.

I not need a Queue.

I want a Stack that "record" the last n element pushed. The oldest must
be overwrite when pushing element when the count exceeds limit.

I need to use this in a Undo scenario. I want to record the action put
them in a Stack. When I make a action I make push,when redo a Pop. If a
make many action without redo, I want to limit my Stack. I want also
that new entry have priority, and oldest can be overwrite.

So the use is LIFO.

PS ha scritto:

> > Hi,
> >
[quoted text clipped - 17 lines]
>
> > It is possbible with this Objet? Or I must make my struct?
Peter Duniho - 23 Nov 2006 19:22 GMT
> [...]
> I need to use this in a Undo scenario. I want to record the action put
> them in a Stack. When I make a action I make push,when redo a Pop. If a
> make many action without redo, I want to limit my Stack. I want also
> that new entry have priority, and oldest can be overwrite.

I'm not sure why people are giving you a hard time about your use of the
term "stack".  It seems appropriate enough, even if you do want your stack
to allow old elements to be able to fall off the other end.

Anyway, seems to me the simplest way to implement your "stack" is to use
some form of a linked list (like, maybe using the LinkedList class :) ).
Designate one end of the list as the top of the stack, and the other as the
bottom.  A double-linked list (such as LinkedList) allows for fast changes
to the list, including retrieving the first and last elements quickly, as
well as adding or removing elements.

So, when you want to push onto the stack, you simply add the element at the
end you've chosen for the top of your stack.  If the length of the stack
exceeds your limit, you remove the element at the end that you've chosen for
the bottom of your stack.

Pete

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.