How do I implement pushdown automaton in C#?

3.5k Views Asked by At

I want to code this for PDA. How would I do that in C#?

a^nbc^n (n>=0) 
1

There are 1 best solutions below

4
On BEST ANSWER

Algorithm:

Read one letter at a time from the input, in a loop.

Stage 1:

If the letter read is "a" then increment a counter, and repeat Stage 1. If the letter read is not "a" then proceed to the next part.

Stage 2:

If the letter read is "b" then proceed to the next stage. If the letter read is not "b" then the algorithm fails.

Stage 3:

If if the letter read is "c" then decrement the counter, and repeat Stage 3. If the letter read is not "c" then proceed to the next stage.

Stage 4:

If the counter is zero, then the algorithm succeeds, otherwise it fails.