| | |
How do i write a word backwards?
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2007
Posts: 74
Reputation:
Solved Threads: 5
•
•
•
•
@curtissumpter: what do you think you are doing giving people ready made code, this forum boasts an attitude opposite of that. Tell the OP the logic mentioning the way to go about, or at the most the psuedocode, but not written code in any manner.
@peedi : Use a stack to reverse the word and I am sure it will be the most convenient approach. Just keep pushing all the letters till the end of the word and then pop them back one by one.
push it all in the stack and pop n print it
Why use a stack? You could just loop through the string and print each char in reverse order.
But still think using the built in StringBuilder is better.
Basically you start at the last character of the string and loop through each character in the String printing in reverse.
But still think using the built in StringBuilder is better.
Java Syntax (Toggle Plain Text)
for (int i=s.length()-1;i>=0;i--) { System.out.print(s.charAt(i)); } System.out.println();
Basically you start at the last character of the string and loop through each character in the String printing in reverse.
•
•
Join Date: Nov 2008
Posts: 25
Reputation:
Solved Threads: 0
•
•
•
•
yup stacks are easiest for that
push it all in the stack and pop n print it
-- LiveWire
•
•
•
•
Why use a stack? You could just loop through the string and print each char in reverse order.
•
•
•
•
But chances are if a person doesn't know how to use str.toCharArray(), they are not going to be familiar with various data structures.
•
•
•
•
If that's the case you could suggest a doubly linked list or whatever
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
•
•
Join Date: Nov 2008
Posts: 25
Reputation:
Solved Threads: 0
We'll have to agree to disagree. You are getting into teaching methods and styles saying that a data structure would be taught before a basic object. I know I wasn't taught data structures until my third course in computer science where as classes and methods (including built in methods) were taught in courses one and two. (Beginning programming and Advanced Programming). But maybe you were taught differently.
And almost any data structure could be used to reverse a string. A variety of trees. A doubly linked list. A stack. So to say "absolutely" when it is not absolute is absolutely wrong.
And almost any data structure could be used to reverse a string. A variety of trees. A doubly linked list. A stack. So to say "absolutely" when it is not absolute is absolutely wrong.
•
•
•
•
We'll have to agree to disagree. You are getting into teaching methods and styles saying that a data structure would be taught before a basic object. I know I wasn't taught data structures until my third course in computer science where as classes and methods (including built in methods) were taught in courses one and two. (Beginning programming and Advanced Programming). But maybe you were taught differently.
And almost any data structure could be used to reverse a string. A variety of trees. A doubly linked list. A stack. So to say "absolutely" when it is not absolute is absolutely wrong.
Also I never said that doubly linked lists cannot be used to reverse strings, you can write a program that uses that damn structure to reverse a string, there can be thousands of different implementations for a single thing and many of them can be absolutely unfitting in the sense that they won't solve the problem in the most optimized, logical way, I said that I haven't heard of they being used for such purpose. You can, for that matter, carry out a poll asking people what is a better DS to be used for string reversal ? Stack/Doubly linked list and then find out that 99.99% of them (all the sane people) would go for a stack.
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
•
•
Join Date: Sep 2008
Posts: 1,619
Reputation:
Solved Threads: 205
I have to disagree with you Curtis. A "Data Structures" course typically assumes that you already have a knowledge of things like stacks and queues, which are generally taught in lower level courses. Not to rehash this argument. And in my opinion, any solution to the problem is helpful, as long as you explain the advantages and disadvantages of each. So there's nothing wrong with telling him how to do it with a doubly linked list as long as he's aware that a stack is probably the more logical way to do it.
![]() |
Similar Threads
- reverse the order of words in a sentence (Pascal and Delphi)
- I found this article on Tips & Tricks (Windows tips 'n' tweaks)
- Huffman coding Issue (C++)
- delphi swap word (Pascal and Delphi)
- Are these features included in Vista (Windows Vista and Windows 7)
- StringUtil (Java)
- palindrome problem (C)
- Help with Palindrome program... (Assembly)
- error C2375: 'my_strdup' : redefinition; different linkage (C++)
- backward string (C++)
Other Threads in the Java Forum
- Previous Thread: switch off the client monitor display
- Next Thread: How to count paragraph for an article?
| Thread Tools | Search this Thread |
-xlint add android api applet application array arrays automation bi binary blackberry bluetooth chat class classes client code compile compiler component converter database digit draw eclipse equation error event exception fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image input int integer j2me java javame javaprojects jetbrains jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying oracle page pattern print problem program programming project qt recursion scanner screen server set size sms sort spamblocker sql string swing system thread threads time tree variablebinding windows xor






