public class CursorList { static CursorNode[] CursorSpace; private static final int SPACE_SIZE = 100; static{ CursorSpace =new CursorNode[SPACE_SIZE]; for (int i = 0; i < SPACE_SIZE; i++) { CursorSpace [i] = new CursorNode(null, i+1); CursorSpace [SPACE_SIZE -1].next =0; } } static private int curorAlloc(){ int p = CursorSpace[0].next; CursorSpace[0].next = CursorSpace[p].next; if(p == 0 ) System.out.println("out of memory"); CursorSpace[p].next =0; return p; } static private void free(int p){ CursorSpace[p].element = null; CursorSpace[p].next = CursorSpace[0].next; CursorSpace[0].next = p; } static public int find(int header , Object x){ int current = CursorSpace[header].next; while (current != 0 && !CursorSpace[current].element.equals(x)) current = CursorSpace[current].next; return current; } static public int findPrevious(int header , Object x){ int current = header; while(CursorSpace[current].next!=0 && !CursorSpace[CursorSpace[current].next].element.equals(x)) current = CursorSpace[current].next; return current; } static public void remove(int header, Object x){ int pos = findPrevious(header,x); if(CursorSpace[pos].next != 0){ int temp = CursorSpace[pos].next; CursorSpace[pos].next = CursorSpace[temp].next; free(temp); } static public boolean isEmpty(int h) { if(CursorSpace == 0) return true; else return false; } } static public void printList ( int header){ if(isEmpty(header)) System.out.println("Empty List"); else{ int current = CursorSpace[header].next; while (current !=0){ System.out.println(CursorSpace[current].element+" "); current = CursorSpace[current].next; } } System.out.println(); } }