Java Reference
In-Depth Information
for ( int i # 0; i < numBlocks; i !! )
queue[i] # numBlocks - i;
first # numBlocks;
}
public void setGUI(DrawingArea drawingArea){
this .drawingArea # drawingArea;
}
int getBlock( int pos) {
if (pos > DIM || pos < # 0) return 0;
return queue[pos-1];
}
int sizeOfFirst() {
if (first ## 0) return 0;
return queue[first-1];
}
public Integer pull() {
// records the state of this tower before the execution
// of method pull()
Tracker.record( this , "pull", Tracker.BEFORE);
// pull the first disc from the peg.
if (first ## 0) return new Integer(0);
int size # queue[first-1];
queue[first-1] # 0;
first - ;
drawingArea.drawingPanel.repaint();
// records the state of this tower after the execution
// of method pull()
Tracker.record( this , "pull", Tracker.AFTER);
return new Integer(size);
}
public void push(Integer size) {
// records the state of this tower before the execution
// of method push()
Tracker.record( this , "push", Tracker.BEFORE);
// push a disc on top of the first disc
if (first ## DIM) return ;
queue[first] # size.intValue();
first !! ;
drawingArea.drawingPanel.repaint();
// records the state of this tower after the execution
// of method push()
Tracker.record( this , "push", Tracker.AFTER);
}
public void restore(Trackable obj) {
this.first # ((Tower) obj).first;
for ( int i # 0; i < DIM; i !! )
this .queue[i] # ((Tower) obj).queue[i];
}
Search WWH ::




Custom Search