⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tsort.hs

📁 Haskell是一种程序语言。特别的
💻 HS
字号:
-----------------------------------------------------------------------------
-- |
-- Module      :  Tsort
-- Copyright   :  Thomas Hallgren?  Lennart Augustsson?
-- 
-- Maintainer  :  Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk>
-- Stability   :  Stable
-- Portability :  All
--
-- partial topological sort
-----------------------------------------------------------------------------

module Tsort(ptsort) where
import Compat(difference)
import List

-- | partial topological sort
--
--		ptsort G sorts the graph G.  A graph is a list of nodes, each
--		node is a pair, a name and a list of names of connected nodes.
--
--		The output is a list of lists, where the lists contain nodes
--		that come before nodes occuring in later lists.
--		The order of nodes within each list is arbitrary and not
--		determined by the graph.
ptsort :: (Eq a) => [(a, [a])] -> [[a]]
ptsort [] = []
ptsort gG =
    case partition (\(_, x) -> null x) gG of
      ([], _) -> error "ptsort: cycle in data\n"
      (a, b) -> let a' = map fst a
                in  a' : ptsort (map (\(x, xs) -> (x, difference xs a')) b)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -