/* Trivial application that displays a string - 4/96 PNL */ public class Maze { public static void main(String args[]) { int [][] maze = new int[5][]; // 00 01 02 03 04 10 11 12 13 14 20 21 22 23 24 30 31 32 33 34 40 41 42 43 44 int [] mazeR00 = {1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int [] mazeR01 = {1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int [] mazeR02 = {0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int [] mazeR03 = {0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int [] mazeR04 = {0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int [] mazeR10 = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int [] mazeR11 = {0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int [] mazeR12 = {0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int [] mazeR13 = {0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int [] mazeR14 = {0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; int [] mazeR20 = {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1,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0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0}; int [] mazeR43 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1}; int [] mazeR44 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1}; maze[0] = mazeR00; maze[1] = mazeR01; maze[2] = mazeR02; maze[3] = mazeR03; maze[4] = mazeR04; maze[5] = mazeR10; maze[6] = mazeR11; maze[7] = mazeR12; maze[8] = mazeR13; maze[9] = mazeR14; maze[10] = mazeR20; maze[11] = mazeR21; maze[12] = mazeR20; maze[13] = mazeR20; maze[14] = mazeR24; maze[15] = mazeR30; maze[16] = mazeR31; maze[17] = mazeR32; maze[18] = mazeR33; maze[19] = mazeR34; maze[20] = mazeR40; maze[21] = mazeR41; maze[22] = mazeR42; maze[23] = mazeR43; maze[24] = mazeR44; // adjacency array is now constructed } // here is class Linked List, and helper class listNode. Note these compile cleanly // but may not be debugged! class ListNode { Object element; ListNode next; ListNode() { } ListNode(Object x, ListNode n) { element = x; next = n; } } class LinkedList { ListNode header; public LinkedList() { header = new ListNode(); } public boolean empty() {return header.next == null; } public void makeEmpty() {header.next = null;} } class LinkedListItr { protected LinkedList theList; protected ListNode current; public LinkedListItr (LinkedList aList) { theList = aList; current = theList.empty() ? theList.header : theList.header.next; } void zeroth() { current = theList.header; } void first() { current = theList.header.next; } void advance() { if (current != null) current = current.next; } boolean isInList () { return current != null && current != theList.header; } void insert (Object x) { if (current == null) return; ListNode newNode = new ListNode(x, current.next); current = current.next = newNode; } boolean find(Object x) { ListNode itr = theList.header.next; while (itr != null && ! itr.element.equals(x) ) itr = itr.next; if (itr == null) return false; current = itr; return true; } void remove(Object x) { boolean foundp = find(x); if (!foundp) return; current.next = current.next.next; current = theList.header; } Object retrieve() { return isInList() ? current.element : null; } } // class vertex for the edge-list representation class vertex { LinkedList arcs = new LinkedList(); vertex() {} void addarc (vertex v) { LinkedListItr litr = new LinkedListItr(arcs); litr.insert (v); } } // class stack as a linked list - again, clean compile only class StackNode { Object item; StackNode link; } class Stack { private StackNode topNode; boolean empty() { return (topNode == null); } Object peek() { if (topNode == null) return null; else return topNode.item; } void push(Object X) { StackNode newNode = new StackNode(); newNode.item = X; newNode.link = topNode; topNode = newNode; } Object pop() { if (topNode == null) return null; else { StackNode tempNode = topNode; topNode = topNode.link; return tempNode.item; } } Object top() { if (topNode == null) return null; else return topNode.item; } } }