Difference between revisions of "Finite State Machine"

From Progzoo
Jump to: navigation, search
(Even Binary Numbers)
(Even Binary Numbers - Absracted)
Line 66: Line 66:
 
  }
 
  }
 
 
   public enum States {START,FAIL,A,B};
+
   public enum States {S,A,B};
 
   public static boolean sm(String s)
 
   public static boolean sm(String s)
 
   {
 
   {
     States state = States.START;
+
     TreeMap<States,TreeMap<String,States>> d =
    TreeMap<States,TreeMap<char,States>> =
+
      new TreeMap<States,TreeMap<String,States>>();
      new TreeMap<States,TreeMap<char,States>>();
+
    d.put(States.S,new TreeMap<String,States>());
 +
    d.put(States.A,new TreeMap<String,States>());
 +
    d.put(States.B,new TreeMap<String,States>());
 +
    d.get(States.S).put("1",States.B);
 +
    d.get(States.A).put("0",States.A);
 +
    d.get(States.A).put("1",States.B);
 +
    d.get(States.B).put("0",States.A);
 +
    d.get(States.B).put("1",States.B);
 +
   
 +
    States state = States.S;
 +
    int i=0;
 +
    while (i<s.length() && state!=null)
 +
    {
 +
      String c = s.substring(i,i+1);
 +
      state = d.get(state).get(c);
 +
      i++;
 +
    }
 
     return state==States.A;
 
     return state==States.A;
 
   }
 
   }

Revision as of 20:55, 16 February 2012

Finite State Machines

Even Binary Numbers


[Font] [Default] [Show] [Resize] [History] [Profile]


Even Binary Numbers - Absracted


[Font] [Default] [Show] [Resize] [History] [Profile]

What is the function


[Font] [Default] [Show] [Resize] [History] [Profile]


What is the function


[Font] [Default] [Show] [Resize] [History] [Profile]

What is the function


[Font] [Default] [Show] [Resize] [History] [Profile]