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: Java Stack Implementation With the Help of Arrays

  1. #1
    Junior Member
    Join Date
    Sep 2021
    Location
    India
    Posts
    20
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Exclamation Java Stack Implementation With the Help of Arrays

    How can I write a program to implement a Stack using Array for this example:

    Example:

    Input: 
    push(2)
    push(3)
    pop()
    push(4) 
    pop()
    Output: 3, 4
    Explanation: 
    push(2)    the stack will be {2}
    push(3)    the stack will be {2 3}
    pop()      poped element will be 3,
               the stack will be {2}
    push(4)    the stack will be {2 4}
    pop()      poped element will be 4

    I need suggestions for this. Thank you!



    Referenece: https://www.scaler.com/topics/stack-class-in-java/
    Last edited by codingkeera; November 16th, 2021 at 08:35 AM.

  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: Java Stack Implementation With the Help of Arrays

    First make a design for how the program will handle a push and a pop.
    What variables does the program need to have to be able to keep track of where the pushed items are stored?
    How do those variables change when an item is pushed?
    How do those variables change when an item is popped?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    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: Java Stack Implementation With the Help of Arrays

    Also posted here: https://coderanch.com/t/746061/java/...on-Arrays-Java
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. stack implementation
    By mosarwa10 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 12th, 2013, 06:22 PM
  2. Stack implementation and shallow copy
    By Shaybay92 in forum Algorithms & Recursion
    Replies: 2
    Last Post: March 20th, 2012, 12:32 AM
  3. Stack implementation with given condition
    By Magesh in forum Member Introductions
    Replies: 2
    Last Post: August 31st, 2011, 01:17 AM
  4. Implementation Stack Using Array
    By rainbow9 in forum Java Programming Tutorials
    Replies: 1
    Last Post: August 20th, 2011, 09:48 AM
  5. help with deque implementation using arrays in java
    By twi in forum Java Theory & Questions
    Replies: 1
    Last Post: June 14th, 2011, 09:55 PM

Tags for this Thread