Is_Simple.w
上传用户:gzelex
上传日期:2007-01-07
资源大小:707k
文件大小:1k
开发平台:

MultiPlatform

  1. documentstyle[11pt,comments]{cweb}
  2. textwidth=6.5in
  3. textheight=9in
  4. oddsidemargin=0in
  5. topmargin=0in
  6. begin{document}
  7. markright{fbox{protecttiny version of today}}
  8. pagestyle{myheadings}
  9. %title{An Implementation of Randomized Search Trees}
  10. %author{Markus Paul}
  11. %date{today}
  12. %maketitle
  13. %tableofcontents
  14. @* Testing simplicity.
  15. noindent
  16. Let $G$ be a graph. We test whether $G$ is simple, i.e. contains no
  17. parallel edges. That is easy to do. We bucket-sort the edges twice:
  18. once according to their source node and once according to their target
  19. node. Since bucket sort is stable this will collect parallel edges.
  20. @c
  21. bool is_simple(graph& G)
  22. {
  23. list<edge>el= G.all_edges();
  24. node v;
  25. edge e;
  26. int n= 0;
  27. node_array<int> num(G);
  28. forall_nodes(v,G) num[v]= n++;
  29. num_ptr= &num;
  30. el.bucket_sort(0,n-1,&epe_source_num);
  31. el.bucket_sort(0,n-1,&epe_target_num);
  32. int i= -1;
  33. int j= -1;
  34. forall(e,el)
  35. { if(j==num[source(e)]&&i==num[target(e)])
  36.   return false;
  37.   else
  38.   { j= num[source(e)];
  39.     i= num[target(e)];
  40.   }
  41. }
  42. return true;
  43. }
  44. @ end{document}