adding and poping from queue, calculating tables S and C; tests not written!!