coloringalgorithm.java

来自「主要功能:对五条道路的车辆进行控制」· Java 代码 · 共 62 行

JAVA
62
字号
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package fivestarcross;import java.util.ArrayList;/** * * @author Dante */public class ColoringAlgorithm {        public ArrayList<Integer> onecolorset;    public ArrayList<VexNode> thegraphcolorset;        public ColoringAlgorithm (ArrayList<VexNode> thegraph){        //默认构造函数        thegraphcolorset   =  thegraph;	}            public void DrawColor(){        //使用贪婪算法对交通图着色		       onecolorset    =   new ArrayList<Integer>();       VexNode tnode;       int count;       boolean flag;        int  si=  thegraphcolorset.size();       int color = 0;       for(count=0;count<si;){           onecolorset.clear();           color++;           for(int i=0;i<si;i++){               tnode=thegraphcolorset.get(i);               if(tnode.vexcolor==0){                   flag=true;                    ArrayList<Integer> first = tnode.firstarc ;                   int fsize = first.size();                   for(int j=0;j<fsize;j++)                       if(onecolorset.contains(first.get(j))){                           flag=false;                           break;                       }                   if(flag){                       tnode.vexcolor = color;                       onecolorset.add(tnode.vexnum);                       count++;                   }               }                              }       }    }}

⌨️ 快捷键说明

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