0

I´m reading how to make a transition table for a NFA. I´m using java and according to my book in order to make the transition table for my NFA I need a two-dimensional array move[s,a] I assume a state s will be an integer and a a symbol from the input (Correct me if I´m wrong). The entries in this table, which are sets of states, are represented by linked lists.

I don´t really know how to declare this on java because arrays can only be of one type.

I´ve been trying with

int[][] move

and

Arraylist<Integer>[][]

But I can´t find the way to map a string symbol to a set of integers. What I would ideally want to accomplish is that I enter for example: move[5,"a"] and get back a set of states (ints) like [5,6,7,9]

Can anyone help me out?

Pablo Estrada
  • 3,182
  • 4
  • 30
  • 74
  • 2
    What have you tried? If you have a piece of code that runs but doesn't do what you want it to, you're welcome to come back and ask for help with the actual code. – s.d Jul 10 '14 at 16:49
  • I´ve been trying with int[][] move, and Arraylist[][]. But I can´t find the way to map a string symbol to a set of integers. What I would ideally want to accomplish is that I enter for example: move[5,"a"] and get back a set of states (ints) like [5,6,7,9] . – Pablo Estrada Jul 10 '14 at 17:19

2 Answers2

1

Maybe something like this?

public class Entry  {
    public int s;
    public String symbol;
}

then

LinkedList<Entry>[][]  twoDimensional;
RalphChapin
  • 3,108
  • 16
  • 18
  • Hi, thanks for the answer. That seem like a good aproach, but I don´t know if it´s a good idea to have the symbols as part of an entry, since the entry shoul just be the states of the NFA. I thinks it should be a way to do it without creating new objects – Pablo Estrada Jul 10 '14 at 17:14
  • @PabloEstrada: You're going to need the class "Entry" somewhere to link a letter and (a) number(s). Maybe making Entry's int s an array (or linked list) of integers rather than one, then taking a dimension off the main array would get you closer. – RalphChapin Jul 10 '14 at 17:29
0

Just use two different one dimensional arrays. If that won't work, use a HashMap.

Michael Barz
  • 276
  • 2
  • 11