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 4 of 4

Thread: stack

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default stack

    hi all
    i have an assignment to check if the stack is palindrum (ex 1 2 3 4 3 2 1 is palindrum 1 2 3 4 5 3 2 1 is not)
    i cant use the method isEmpty and i can use only another stack
    so my question is how the hell i do that?
    i thought to use the other stack like i transfere hlaf of the first stack to the other and then compare between them but it doesn't work beacuase i get out of order
    so help me plz


  2. #2
    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

    What have you done so far? Break the problem down to the smallest pieces...you will have to compare the first half and the second half of the string (in reverse). How would you go about doing this? Placing each half in its own stack? Iterate over the first stack in reverse? Try and if you get stuck post some code with any errors or wierd behavior

  3. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: stack

    i dont know when i get to the half thats my problem
    i thought about what u say but the problem that i dont know when i get to the half and to the end of tha stack

  4. #4
    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

    Review the API's for String and Stack. Each has methods that will be useful, for example String.length() can let you know when you've reached the halfway point. This is what I mean by breaking the problem down...ask specific questions like 1) I need to know where the 'halfway point' in a string is...if I knew the length then I can get half the length (divide by 2)...then how do I get the length of the string? Once I have that, how can I loop over the string? How do I get the character at a specific position? Each of these can be answered using the links above as a reference. Ask one question at a time and build off of each.

Similar Threads

  1. Stack
    By AmyH in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 7th, 2010, 04:04 PM
  2. Stack Array..
    By qaromi in forum Collections and Generics
    Replies: 2
    Last Post: December 26th, 2009, 12:54 PM
  3. Stack Order?
    By TimW in forum AWT / Java Swing
    Replies: 2
    Last Post: September 19th, 2009, 07:33 AM
  4. Error of "cannot access InToPost" in 3 and 5 code
    By jaysoncutie in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 25th, 2009, 09:12 AM
  5. Replies: 0
    Last Post: October 14th, 2008, 06:40 PM