Results 1 to 3 of 3

Thread: [2005] Last in First Out arraylist

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Location
    Devon - UK
    Posts
    214

    [2005] Last in First Out arraylist

    I need to add items to an arraylist until the count gets to, for example, 100 and then read them on a Last in first out basis.

    ow do I achieve this?

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Last in First Out arraylist

    First off, in VB 2005, you should never use the ArrayList, if you need a collection you should use the List(Of T).
    However, in this scenario, you should use a collection that is created for this purpose:
    VB.NET Code:
    1. System.Collections.Generic.Stack(Of T)
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] Last in First Out arraylist

    Before add an item to your array list, you check the Count property to see if it reaches the limit. If it doesn't, add the item. Else, don't add. Now to read the items LIFO, you just need a For loop running backward from arraylist.count - 1 to 0.

    EDIT: If you can use something other than an arraylist, I strongly suggest you to use a stack as Atheist said.
    Last edited by stanav; May 2nd, 2008 at 12:47 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width