home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Journal 1990 - 1995 / CUJ.iso / image90 / 9006t1f1.pcx (.png) < prev    next >
PC Paintbrush Image  |  1996-01-31  |  42KB  |  320x494  |  4-bit (4 colors)
Labels: text | screenshot | font | number | black and white | document
OCR: " Algorithm for topological sort Input: a set of ordered pairs that represents a partial order. Output: a total order in which the partial order is embedded. * Data structures Assume a dictionary of items to be sorted. Must be able to store with cach iten the number of its predecessors and a pointer to a linked list of its successors in the partial order. Based on algorithm given in Data Structures and * C Programs, C.J. Van Wyk "initialize data structures For Each ordered pair (a, b) in the input Add 1 to b's count of predecessors Add b 'to a's list of successors End For Enqueue each item that has no predecessors Construct topological order While the queue is not empty For Each successor of item at the head of the queue Subtract 1 from its predecessor count f If its predecessor count is zero :Enqueue it End If End For Dequeue and output the iten at the head of the queue End While