Advertisement
Guest User

Untitled

a guest
Apr 15th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. class Tape {
  2.   char[] right;
  3.   char[] left;
  4.   Tape() {
  5.     right = new char[0];
  6.     left = new char[0];
  7.   }
  8.   char get(int index) {
  9.     if (index >= 0) {
  10.       if (index >= right.length) {
  11.         return BLANK;
  12.       }
  13.       return right[index];
  14.     }
  15.     else
  16.     {
  17.       if (-index - 1 >= left.length) {
  18.         return BLANK;
  19.       }
  20.       return left[-index - 1];
  21.     }
  22.   }
  23.   void set(int index, char state) {
  24.     if (index >= 0) {
  25.       if (index >= right.length) {
  26.         right = expand(right, index + 1);
  27.       }
  28.       right[index] = state;
  29.     }
  30.     else
  31.     {
  32.       if (-index - 1 >= left.length) {
  33.         left = expand(left, -index);
  34.       }
  35.       left[-index - 1] = state;
  36.     }
  37.   }
  38. }
  39.  
  40. static final char BLANK = ' ';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement