Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: STACK USING LINKED LIST------------HELP !

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default STACK USING LINKED LIST------------HELP !

    hello i m jayesh.,.....can somebody help me with this......


    import java.io.*;

    class StackNode
    {
    Object info;
    StackNode next=null;
    StackNode prev=null;
    StackNode(Object el)
    {
    info=el;
    }
    }

    class Stack
    {
    StackNode head,tail;
    Stack(){}

    boolean isEmpty()
    { return head==null;}

    void push(Object el)
    {
    if(isEmpty())
    head=tail=new StackNode(el);
    else
    {
    tail.next=new StackNode(el);
    tail.prev=tail;
    tail=tail.next;
    }
    }

    Object pop()
    {
    Object el;
    el=tail.info;
    tail=tail.prev;
    return el;
    }

    Object peek()
    { return tail.info;}
    }

    class StackUsingLinkedList
    {
    public static void main(String args[])throws IOException
    {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    int x,in;

    Stack s=new Stack();

    System.out.println("STACK IMPLEMENTATION USING INT ARRAY");

    do
    {
    System.out.println("\n\nENTER CHOICE\n1.PUSH 2.POP 3.PEEK 4.EXIT");
    x=Integer.parseInt(br.readLine());

    switch(x)
    {
    case 1:
    System.out.println("Enter an integer");
    in=Integer.parseInt(br.readLine());
    s.push(in);
    break;

    case 2:
    if(!s.isEmpty())
    System.out.println("Element at the top of the stack : "+s.pop());
    else
    System.out.println("Stack is Empty");
    break;

    case 3:
    if(!s.isEmpty())
    System.out.println("Element at the top of the stack : "+s.peek());
    else
    System.out.println("Stack is Empty");
    break;

    case 4:
    break;
    }
    }
    while(x!=4);
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: STACK USING LINKED LIST------------HELP !

    Please post coding questions in the appropriate section of the forum. This one is for introductions.

    You need to explain what the problem is in detail. If it gets errors, copy and paste the full text on the forum.

    Also wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: STACK USING LINKED LIST------------HELP !

    Thread moved from members introductions.

    Suggested reading: http://www.javaprogrammingforums.com...-get-help.html

Similar Threads

  1. linked list
    By javasohard in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 18th, 2011, 02:22 AM
  2. Linked list Schminked list help with Nodes Please
    By Bially in forum Collections and Generics
    Replies: 1
    Last Post: September 29th, 2011, 03:20 PM
  3. linked list help
    By tjoney in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 3rd, 2011, 06:54 PM
  4. [SOLVED] Linked List Help
    By lieles in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 4th, 2011, 10:32 PM
  5. Recursive function based on Linked list
    By rosh72851 in forum Collections and Generics
    Replies: 1
    Last Post: March 9th, 2009, 06:23 PM

Tags for this Thread