2 Replies - 333 Views - Last Post: 13 September 2011 - 02:35 AM Rate Topic: -----

#1 litha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-February 09

use of a link list containing names and display reversed

Posted 13 September 2011 - 01:46 AM

I am actually lost on a program that i have to develop and don't know to start. the program suppose to make use of a link list that must contain ten names entered by the user and must be display reversed at the later stage. The user input should be an input dialog box and the result should show the entered names and the reversed names in a message box.

Thanks for helping...
Is This A Good Question/Topic? 0
  • +

Replies To: use of a link list containing names and display reversed

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: use of a link list containing names and display reversed

Posted 13 September 2011 - 02:32 AM

What you need is creating a linked list of strings, ask user for input and store them in that list. Then you can display them using index from the last .length() -1 to 0. Have a look at:
Linked List Tutorial
Linked List Documentation
If you have any problem or something you dont get it clearly, feel free to ask for it.
Was This Post Helpful? 0
  • +
  • -

#3 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 284
  • View blog
  • Posts: 1,617
  • Joined: 15-May 08

Re: use of a link list containing names and display reversed

Posted 13 September 2011 - 02:35 AM

Well in terms of dialog box i am guessing you could use JOptionPane.showInputDialog("Enter Name"); found in javax.swing.

Assuming you are allowed to use the API for your linked list you may consider looking at java.util.LinkedList and simply use it to handle your LinkedList (only if you do not need to implement your own LinkedList)

Basically you will end up having a loop that executes 10 times and on each iteration you add the entered name to the end of the list. When you then need to print out the contents you will use a the methods of the LinkedList to find the length and iterate it from the end to head nodes. This will allow you print out the names entered in reverse order. If you need to print the actual name in reverse eg 'litha' as 'ahtil' then you could consider using StringBuffer(String str).reverse();

eg.
String str = "litha";
String rev = StringBuffer(str).reverse();



Good luck, post back if you have any issues.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1