Results 1 to 2 of 2
  1. #1
    mackavelirip is offline Member
    Join Date
    Feb 2011
    Rep Power

    Default Stack with nodes question

    I recently took a test for my class and got the test back and got this part of the test all wrong

    Java Code:
    public class Stack<E>
           static class SNode<T>
                 T data;
                 SNode<T> next;
                 SNode(T d, SNode<T n>
                     data = d;
                     next = b;
            private SNode<E> top; //pointer to top of stack
            private int size;
            void push(E elt){ /*this needs to be defined */}
    SNode<E> tmp = new SNode<E>(); = top;
    top = tmp; = elt;

    SNode<E> tmp = new SNode<E>();
    top = tmp; = top; = elt;

    top = new SNode<E>(elt,top);

    The question is whether those are the correct body for the push method. Those are the ones I got wrong so if anyone can help id appriciate it.
    If you can give me step by step instructions on what points to what and how that means its a valid push method id appriciate it.

    Oh and the answers are yes, no, and yes.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Rep Power

    Default Re: Stack with nodes question

    Better yet, why don't you explain, step for step, what you think needs to happen, and then we will help you to correct that.

Similar Threads

  1. Inserting Nodes
    By myst in forum New To Java
    Replies: 2
    Last Post: 07-12-2010, 04:26 PM
  2. Problem with Nodes - need help!
    By Smithy in forum New To Java
    Replies: 3
    Last Post: 03-20-2010, 03:47 PM
  3. How to dynamically add Nodes to JTree?
    By javanewbie in forum AWT / Swing
    Replies: 3
    Last Post: 07-13-2009, 07:20 AM
  4. nodes
    By Dr Gonzo in forum New To Java
    Replies: 1
    Last Post: 12-08-2008, 04:22 PM
  5. nodes in java
    By ahsan in forum New To Java
    Replies: 0
    Last Post: 12-26-2007, 03:09 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