Note that there are some explanatory texts on larger screens.

plurals
  1. POStacks dealing racognizng strings in a language, keep getting error, it's a array based implementation
    primarykey
    data
    text
    <p>I am trying to implement an algorithm "recongnizng strings in a languages "</p> <blockquote> <p>L = {'w$w' : w is a possible empty string of characters other than $, w' = reverse(w)}</p> </blockquote> <p>I get an error saying where <code>ch = aString[i];</code> : the type of expression must be an array type but resolved to string</p> <p>also where <code>stackTop = aStack.pop();</code> but here however it's asking to cast to char</p> <p>' import java.util.Stack;</p> <p>public class Stacks {</p> <pre><code>public static void main(String[] args){ boolean eval = isInLanguage("sod$dos"); System.out.println(eval); } static // astack.createStack(); boolean isInLanguage(String aString){ Stack&lt;Character&gt; aStack = new Stack&lt;&gt;(); int i = 0; char ch = aString.charAt(i); while (ch != '$') { aStack.push(ch); i++; } //Skip the $ ++i; // match the reverse of w boolean inLanguage = true; // assume string is in language while (inLanguage &amp;&amp; i &lt; aString.length()) { char stackTop; ch = aString.charAt(i);; try { stackTop = (char) aStack.pop(); if (stackTop == ch) { i++; } else { // top of stack is not ch(Charecter do not match) inLanguage = false; // reject string } } catch (StackException e) { // aStack.poo() failed, astack is empty (first, half of Stirng // is short than second half) inLanguage = false; } } if (inLanguage &amp;&amp; aStack.isEmpty()) { return true; } else{ return false; } } </code></pre> <p>}</p> <p>'</p> <p>I just made the necessary changes but now, it will compile but it doesnt seem to stop and doesn't output anything, i am expecting a true in the console</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload