Opiskelija simuloi janojen risteyskohdat etsivää pyyhkäisyviiva-algoritmia. Hän ylläpitää tapahtuma- ja naapuripuuta.
1. Initialize priority queue Q 2. Initialize adjacency structure A 3. Add all segment endpoints to Q 4. while Q is not empty 5. Take next event point p from Q 6. let s be the line segment corresponding to p 7. if p is the first endpoint of s 8. add s to A and let r and t be its neighbours in A 9. if r and s intersect, add the intersection to Q 10. if s and t intersect, add the intersection to Q 11. else if p is the second endpoint of s 12. remove s from A and let r and t be its former neighbours in A 13. if r and t intersect at a point where X-coordinate is greater than the X-coordinate of p AND the intersection has not been discovered before 14. add intersection to Q 15. else if p is an intersection point, where s and t are the intersecting lines 16. swap s and t's positions in A 17. let r be the new neighbour of t in A, and u be the new neighbour of s in A 18. if r and t intersect at a point where X-coordinate is greater than the X-coordinate of p AND the intersection has not been discovered before 19. add intersection to Q 20. if s and u intersect at a point where X-coordinate is greater than the X-coordinate of p AND the intersection has not been discovered before 21. add intersection to Q 22. add p to output