Jump to content
xisto Community
Sign in to follow this  
kvarnerexpress

Recursion Using A Linkedlist

Recommended Posts

I am confused at how to make a linked list using recursion. I've been looking at the syntax and examples from the web for the past couple hours, but all seem to be based on an empty .java file. I need to put it in my code somehow. here's the code segment:

public static boolean RecursiveTest (String s, int start, Node n) {// The linked listNode<char> bracket = new Node<char>();int size = s.length();char v = s.charAt(start);//String sElement = parens.top();boolean isGood = true;// ending "ifs"if (size == 0) { System.out.println("empty string"); return false; }if (start == size) return isGood;if (s.charAt(start) == '(' || s.charAt(start) == '[' ||s.charAt(start)== '{') {v.Push(sChar);System.out.println(sChar);return RecursiveTest(start+1, s.charAt(start));}else if (sChar.equals(")") && sElement.equals("(")) {parens.Pop();System.out.println(sChar);return RecursiveTest(start+1);}else if (sChar.equals("]") && sElement.equals("[")) {parens.Pop();System.out.println(sChar);return RecursiveTest(start+1);}else if (sChar.equals("}") && sElement.equals("{")) {parens.Pop();System.out.println(sChar);return RecursiveTest(start+1);}else if (sChar.equals(")") && !sElement.equals("(")) {System.out.println("bad");isGood = false;return isGood;}else if (sChar.equals("]") && !sElement.equals("[")) {System.out.println("bad");isGood = false;return isGood;}else if (sChar.equals("}") && !sElement.equals("{")) {System.out.println("bad");isGood = false;return isGood;}else return RecursiveTest(start+1);} // end of RecursiveTest


I'm passing a string, 0, and a new node (i dunno about the last one there), from an above main class.

This code is wrong, i know, but it's all I got done so far. How would I be able to make a linked list inside this method?

NOTE: the Push() and Pop() are remnants from copy-paste from my stack method above that uses the same if and else-if statements. I need to replace them with the correct code for a working linked list
Thanks,kvarnerexpress

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.