iterate n-1 times { for the ith element (i ranging from 0 to n-1-1) { if (out of order (relative to the i+1th element) swap ith and ith+1th values } }
while out of order (globally) { for the ith element (i ranging from 0 to n-1-1) { if (out of order (relative to the i+1th element) swap ith and ith+1th values } }
s = n/3; // set the initial gap size while out of order (globally) { for the i ranging from 0 to n-s-1 { if (out of order (relative to the i+sth element) swap ith and ith+sth values } s = s/2+1 // reduce the step size }
void paint(Graphics g) { // very much like paint(Graphics) in Conway's life drawLines(g); // g.drawLine(x1, y1, x2, y2); drawPieces(g); // g.drawString("X", x, y); }