Results 1 to 3 of 3
  1. #1
    ai_2007 is offline Member
    Join Date
    Jun 2007
    Posts
    21
    Rep Power
    0

    Default Creating a stack with data

    I have to create a class 'Dear' that has a stack that will allow addition of 'event' information into it. The event information will include event type and date of event. All the data has to be sorted automatically while it is being added into the stack.

    Please help me with this because I am not sure of how to do this.

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    All the data has to be sorted automatically while it is being added into the stack.
    If the stack objects need to be sorted then it is not called as stack anymore and implementing a stack for that purpose is unnecessary. Just use an ArrayList or Vector and while inserting an element search for the correct position and call insert method.

    If there are some performance issues, you might search for a better data structure since, in my way, insertion can be slow when lots of data exist in a vector.

  3. #3
    ai_2007 is offline Member
    Join Date
    Jun 2007
    Posts
    21
    Rep Power
    0

    Default Better data structure

    You mentioned implementing a better data structure for more data.
    Could you please illustrate what you mean by better data structure with the algorithm given?

Similar Threads

  1. Stack data structure in Java
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 10:34 PM
  2. Replies: 0
    Last Post: 01-03-2008, 12:28 PM
  3. Stack Trace
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-10-2007, 05:29 PM
  4. Help Creating A Graph From Inputted Data
    By adlb1300 in forum New To Java
    Replies: 6
    Last Post: 10-28-2007, 04:45 AM
  5. Help with heap and stack
    By coco in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 02:21 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
  •