# takes O(n) time. for [ i = 0 to a.size() - 1 ] a[i] = i
# takes O(1) time. co [ i = 0 to a.size() - 1 ] a[i] = i
for [ i = 1 to a.size() - 2 ] a[i] = (a[i - 1] + a[i] + a[i + 1])/3
bool board[2, rows, cols] bool step(int bno, int r, int c) int neighbors = 0 if board[bno, r - 1, c - 1] then neighbors++ if board[bno, r - 1, c] then neighbors++ if board[bno, r - 1, c + 1] then neighbors++ if board[bno, r, c - 1] then neighbors++ if board[bno, r, c + 1] then neighbors++ if board[bno, r + 1, c - 1] then neighbors++ if board[bno, r + 1, c] then neighbors++ if board[bno, r + 1, c + 1] then neighbors++ return neighbors == 3 or neighbors == 4 int main() co [ r = 0 to rows - 1, c = 0 to cols - 1 ] board[0, r, c] = false for [ r = 0 to rows - 1 ] readrow(0, r) int current = 0 while true output(current) int next = (current + 1) % 2 co [ r = 1 to rows - 2, c = 1 to cols - 2 ] board[next, r, c] = step(current, r, c)
int pivot(int a[], left, right) int m = (right - left)/2 # a[left..m - 1] <= a[m] < a[m + 1..right] return m void qsort(int a[], int left, int right) if right - left < 2 skip else if right - left == 2 if a[left] > a[right] swap(a[left], a[right]) else m = pivot(a, left, right) co qsort(a, left, m) // qsort(a, m + 1, right) oc int main() int a[] = read() qsort(a, 0, a.size())
queue mailboxes[n]; void worker1(int i) while true msg m = get.mailboxes[i] m = f(m) if p(m) mailboxes[3].put(m) else mailboxes[5].put(m) int main() co worker1(1) // worker1(2) // worker2(3) // ... oc
$ cat cc-high-rstat.cc #include <rpcsvc/rstat.h> int main(int argc, char * argv[]) const int dsk = havedisk(argv[1]); if (dsk < 0) cerr << "havedisk(" << argv[1] << ") failed.\n" return EXIT_FAILURE cout << argv[1] << (dsk ? "has" : "doesn't have") << " a disk.\n"; $ uname -a SunOS clayton 5.7 Generic_106541-11 sun4u sparc SUNW,Ultra-5_10 $ cc-high-rstat cslab05 cslab05 has a disk. $ cc-high-rstat clayton clayton has a disk. $ cc-high-rstat starbase.se.monmouth.edu starbase.se.monmouth.edu has a disk.
procedure read(queue q) while !eof q.put(read()) q.put(stop) procedure work (queue in, queue out) while true x = in.get() if x == stop, break out.put(f(x)) out.put(stop) procedure write(queue q) while true x = q.get() if x == stop, break write(x) procedure main() queue read2work, work2write co read(read2work) || work(read2work, work2write) || write(work2write) oc
This page last modified on 29 May 2003.