Computer Science Canada

linked list data

Author:  bryce_21 [ Thu May 01, 2014 10:32 am ]
Post subject:  linked list data

Objectives:
(1) demonstrate the ability to write, compile, and run a simple Java program.
(2) solve a simple problem using recursion.
(3) demonstrate the ability to use recursion.
(4) demonstrate the ability to diagram a Java program.
Instructions:
A. Set up the compiler on your workstation.
B. Write, compile, and run a Java program that:
(1) prompts the user to type a 5 characters such as a 5 digit number,
(2) calls a parameterless. void, recursive function named "reverse" to print the
number backwards.
C. Diagram (i.e. illustrate with a picture) your program completely.
D. e-mail your source code to me.

need help coming up with an algorithm for this project

Author:  Insectoid [ Thu May 01, 2014 10:54 am ]
Post subject:  RE:linked list data

Well, have you tried anything?

Author:  Raknarg [ Thu May 01, 2014 1:52 pm ]
Post subject:  RE:linked list data

Also, out of curiosity what does the title have to do with the question?

Author:  Tony [ Thu May 01, 2014 3:11 pm ]
Post subject:  Re: linked list data

I would guess that has to do with someone's idea of storing a string as a linked list of characters Laughing

Author:  bryce_21 [ Wed May 07, 2014 8:29 pm ]
Post subject:  Re: linked list data

here what came up when i try storing strings of characters in linked lists

import java.util.Scanner;
public class Reversetest
{
public static String inputstr;
public static int n = 5;

public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
inputstr = keyboard.nextLine();
reverse();
}
public static void reverse()
{

if (n >= 0)
{
System.out.println(inputstr.charAt(n-1));
n--;
reverse();
}
else
{
System.exit(0);
}

}
}

Author:  Tony [ Thu May 08, 2014 1:04 pm ]
Post subject:  RE:linked list data

code:

System.out.println(inputstr.charAt(n-1));

Since you are indexing into the string anyway, this is effectively a for-loop. Figuring out how to use e.g.
code:

System.out.println(inputstr.charAt(0));

should give you a better feel for recursion.


: