Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Tape {
- char[] right;
- char[] left;
- Tape() {
- right = new char[0];
- left = new char[0];
- }
- char get(int index) {
- if (index >= 0) {
- if (index >= right.length) {
- return BLANK;
- }
- return right[index];
- }
- else
- {
- if (-index - 1 >= left.length) {
- return BLANK;
- }
- return left[-index - 1];
- }
- }
- void set(int index, char state) {
- if (index >= 0) {
- if (index >= right.length) {
- right = expand(right, index + 1);
- }
- right[index] = state;
- }
- else
- {
- if (-index - 1 >= left.length) {
- left = expand(left, -index);
- }
- left[-index - 1] = state;
- }
- }
- }
- static final char BLANK = ' ';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement