Results 1 to 6 of 6
  1. #1
    Srcee is offline Member
    Join Date
    Oct 2009
    Posts
    14
    Rep Power
    0

    Default Help with stacks

    Stack is a Last-in-first-out structure. Let's implement it with single linked list. Would it be a mistake if we add methods for removing/adding element in the middle/beggining of the list?

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    What do you think?

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,730
    Blog Entries
    7
    Rep Power
    21

    Default

    It would be a stack on steroids.

    kind regards,

    Jos

  4. #4
    Srcee is offline Member
    Join Date
    Oct 2009
    Posts
    14
    Rep Power
    0

    Default

    It wouldn't be a mistake because we can add/remove elements from the middle of a single linked list

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,730
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Srcee View Post
    It wouldn't be a mistake because we can add/remove elements from the middle of a single linked list
    A stack doesn't need to be implemented by a single linked list. Purists may say that you can push and pop elements to/from a stack and that's it. A more practical approach might say that more operations on stacks should be possible. The Stack implementation in Java is quite weak because behind its back you can cast a Stack to its parent class, a Vector; you can do much more with a Vector than you can do with a Stack.

    kind regards,

    Jos

  6. #6
    Srcee is offline Member
    Join Date
    Oct 2009
    Posts
    14
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    A stack doesn't need to be implemented by a single linked list. Purists may say that you can push and pop elements to/from a stack and that's it. A more practical approach might say that more operations on stacks should be possible. The Stack implementation in Java is quite weak because behind its back you can cast a Stack to its parent class, a Vector; you can do much more with a Vector than you can do with a Stack.

    kind regards,

    Jos
    Tnx so much

Similar Threads

  1. 2 stacks, the second keeps mirroring the second??
    By jigglywiggly in forum New To Java
    Replies: 7
    Last Post: 10-11-2009, 08:31 AM
  2. Arithmetic Stacks
    By unc123w in forum New To Java
    Replies: 22
    Last Post: 10-21-2008, 09:24 PM
  3. Stacks, lists...
    By little_polarbear in forum New To Java
    Replies: 7
    Last Post: 08-02-2008, 02:59 PM
  4. Stacks
    By Zosden in forum Advanced Java
    Replies: 15
    Last Post: 05-05-2008, 09:16 AM
  5. Using Stacks
    By ravian in forum New To Java
    Replies: 7
    Last Post: 11-28-2007, 10:53 AM

Posting Permissions

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