Program yang digunakan untuk mewarnai peta USA dengan menggunakan bahasa

pemrograman java:

36. map[35] = new int[] {31.49. map[50] = new int[] {0. map[25] = new int[] {26}.32.17.42.14}. map[9] = new int[] {10.2}.45.29.13.46}. map[14] = new int[] {13.29.15.49}. map[1] = new int[] {16. map[22] = new int[] {8.11.35. } static final int NONE = 0. map[2] = new int[] {1.39.13}.33.24. map[40] = new int[] {41.19. map[48] = new int[] {0.33. map[20] = new int[] {7.4.20.4.5}. map[38] = new int[] {39.40.35}.31. map[26] = new int[] {25}. map[44] = new int[] {41.45. map[4] = new int[] {3. map[10] = new int[] {9. map[37] = new int[] {35.33.16.29.33.28}.34. map[3] = new int[] {2.23}.46. map[29] = new int[] {22.45. map[42] = new int[] {17. map[32] = new int[] {20.50.27.42.13}. map[30] = new int[] {27.18.36}.27.40.40.39.28.42.18. map[0] = new int[] {16.19.45.19.23}. map[39] = new int[] {33.18.Source Code public class ColoredMap { int map[][].50}.33.40}.46}.22}.21.32. .23. map[46] = new int[] {47.43.50. map[5] = new int[] {4.48. map[12] = new int[] {11}.22}. map[24] = new int[] {9. void createMap(){ map = new int[51][].50. map[43] = new int[] {17.37.47}.47}.33.2. map[16] = new int[] {1.11. map[7] = new int[] {5.40.38}.21.30}.17}.17}.21}.17.22.43}.48.14}.28.7.47.29.12.41.10. map[45] = new int[] {43.18}. map[33] = new int[] {41. map[13] = new int[] {9.35.23}.30}.3.30.38.50}. map[19] = new int[] {5.49. map[17] = new int[] {2.3. map[23] = new int[] {9.43.45.18.35}.22.37}. map[11] = new int[] {10.36.20.40}. map[41] = new int[] {20.20}.32.32.32}.41.42.44}. map[47] = new int[] {48. map[31] = new int[] {30.19}. map[21] = new int[] {8.41.18}.46}. map[28] = new int[] {23. map[15] = new int[] {9. map[6] = new int[] {7}.0}.13. map[49] = new int[] {2.44.6.24.45. map[18] = new int[] {3. map[36] = new int[] {39.15.15}.43.34}.29.32.30.42.41.2.19.42.28.16}.19}.32.38.48. map[8] = new int[] {21.5.7.44.31}.30.43.49. map[27] = new int[] {23.44. map[34] = new int[] {31.49}.33.41}.36.

length.print("map["+i+"] adalah "). } .printMap(). } if(okToColor(country.println("RED").NONE. RED = 3.NONE. YELLOW = 4.NONE.NONE. boolean result = m.NONE.NONE.NONE.NONE. case RED : System.NONE.color)) { mapColors[country] = color. break. i++) { System. case YELLOW : System. NONE. GREEN = 2. void printMap() { for(int i=0.length) return true. if(mapColors[ithAdjCountry] == color) return false. int color) { for(int i=0. System.NONE.out.NONE. break.NONE}. break. } } return false.NONE.NONE. case GREEN : System. } } } } public static void main(String args[]) { ColoredMap m = new ColoredMap().NONE. i<map[country].NONE.NONE.NONE. RED).println("NONE").static static static static final final final final int int int int BLUE = 1.NONE. for(int i=BLUE.println("YELLOW").NONE.NONE.NONE. m.i)) return true.out.NONE. } return true. i++) { int ithAdjCountry = map[country][i].out.NONE.NONE.out. boolean okToColor(int country. int mapColors[]={NONE.NONE.println(result).NONE.NONE. break. break.NONE.explore(0. int color) { if(country >= map.NONE.NONE. NONE.NONE. NONE.NONE. i++){ if(explore(country+1.NONE.println("GREEN").createMap(). } boolean explore(int country. NONE. m.NONE.NONE. i<=YELLOW.NONE.NONE. case BLUE : System.NONE.println("BLUE"). switch(mapColors[i]){ case NONE : System.NONE.NONE.length. i<mapColors.NONE.out.NONE.out.NONE.out.NONE.NONE.

Output dari program (Pewarnaan) : .

Peta USA yang akan diwarnai: Peta USA setelah diwarnai: .

Sign up to vote on this title
UsefulNot useful