数据结构与算法-看得见的算法 课程设计报告.docx
《数据结构与算法-看得见的算法 课程设计报告.docx》由会员分享,可在线阅读,更多相关《数据结构与算法-看得见的算法 课程设计报告.docx(23页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、信息工程系综合课程设计报告题 目:班 级:学 号:姓 名:指导老师:数据结构与算法.看得见的算法软件与信息服务四班19023038成林诗睿四、附件核心代码,图一:koch雪花分形public AlgoVisualizer(int depth, int side)A8 * vdata = new FractalData(depth);int scenewidth = 3*side+3; int sceneHeight = side;EventQueue.invokeLater() - -frame = new AlgoFrame( title: Fractal Visualizer1, scen
2、ewidth、sceneHeiqht): frame.addKeyListener(new AlgoKeyListenerO);二new Thread() - run(); ?).start(); ?); ? private void run() setData(data.depth); ? private void setData(int depth) data.depth = depth; frame.render(data); AlgoVisHelper.pause(DELy);throw new IllegalArgumentException(Text is null in draw
3、Text function!);FontMetrics metrics = g.getFontMetricsO;int w = metrics.stringWidth(text);int h = metrics.getDescentO;g.drawstring(text, x: centerx - w/2, y: centery + h);?public static void fillTriangle(Graphics2D g, int xl, int yl, int x2, int y2, int x3GeneralPath path = new GeneralPathO;path.mov
4、eToCxl, yl);path.lineTo(x2r y2);path.lineToCxS, y3);path.closePathO;g.filKpath);public static void drawLine(Graphics2D g, double xl, double yl, double x2, double y2:Line2D line = new Line2D.Double(xlr yl, x2, y2);g.draw(line);Fractal Visualizer二:扫雷2347707172737475767778790Override public String toSt
5、ringO return Person +name= + name +,age= + age +,gender= + gender + ,id=H + id +public static void main(String args) List personList = new ArrayList( initialcapacity: 3);-Scanner scanner = new Scanner(System.in); int n = scamuer.nextlntO;-for (int i = 0; i System. out. printin (person. toStringO);10
6、6789 ie ii121314151617181926212223242526272829A 10private static int DELAY = 5;private static int blockside = 32;private MineSweeperData data;private AlgoFrame frame;private static final int d =public AlgoVisualizer(int N, int M, int mineNumberXdata = new MineSweeperData(N, M, mineNumber);int scenew
7、idth = M * blockside;int sceneHeight = N * blockSide;EventQueue.invokeLater(.O - frame = new AlgoFrame( title: HMine Sweeper, scenewidth、sceneHeiqht):new Thread() - run();) .start。;);private void run()11JJJJIIkJnMine Sweeperr*-U制rrir圜J三:推箱子J厂厂厂JllJ12JJIJ*B且JJrir hjJJiIBiLJFlI8916private private6 pub
8、lic class AlgoVisualizer static int DELA=5;static int blockSide = 89121314161819 2G042324282930private privateGameData data;AlgoFrame frame;public AlgoVisualizer(String filename) data = new GameData(filename);int scenewidth = data.NO * blockSide)int sceneHeight = data.NO * blockSide;EventQueue.invok
9、eLater() - frame = new AlgoFrame( title: Move the Box Solver, scenewidth,sceneHeiqht):new Thread() - run();),start(););private void run()13public AlgoVisualizer(String filename)(data = new GameData(filename);int scenewidth = data.MO * blockSide)int sceneHeight = data.NO * blockSide;EventQueue.invoke
10、Loter() - frame = new AlgoFrame( title: Move the Box Solver, scenewidth, sceneHeight);new Thread() - run();).start();); private void run()setDataO;if (data.solveO)System.out.println(The game has a solution!;elseSystem.out.printin(The game does NOT have a solution.);setDataO;, BCB., BCB.ADA.BDECBDFAF
11、CBAAEFEB.A. B A. . B BAB. .BAB. .ABA.14四:走迷宫nMr35go(data.getEntranceX(), data.getEntranceY();ak - setData( x: -1, y: -1);_39Tprivate void go(int x, int41if(!data.inArea(x,y)throw new IH.egalArgumentException(x,y are out of index in go furtC 44data.visitedxy = true;setData(x( y);47if(x = data.getExit
12、XO & y = data.getExitYO)49return;for(int i = 9 ; i 4 ; i +)int newX = x + di6; int newY = y dll; if(data.inArea(newX, newY) & data.getMaze(newX,newY) = NazeData.ROAD & !data.visitednewXnewY)57 0goCnewX, newY);60returl;private boolean go(int x, int y)-aif(!data.inArea(x,y)throw new IllegalArgumentExc
13、eption(x,y are out of index in go fuirt Idata.visitedxy = true; setData(x, y, isPath: true);if(x = data.getExitXO & y = data.getExitYO) return true;for(int i. = 8 ; i v 4 ; i +)int newX = x di0;int newY = y dil;if(data.inArea(newX, newY) &data.getMaze(newX,newY) = MazeData.R04D & !data.visitednewXne
14、wY) if(go(newX, newY) return true;/回溯setData(x, y, isPath: false);return false;15鼻二二-一1”.一堆甘郢氏,01,令);AW A1 * V XIStack stack = new Stack();_ gPosition entrance = new Position(data.getEntranceXO, data.getEntranceY | stack.push(entrance);一,data.visitedentrance.getX()entrance.getY() = true;while(! stac
15、k, empty ()Position curPos = stack.pop();二setData(curPos.getX(), curPos.getY(), isPath: true);if(curPos.getX() = data.getExitXO & curPos.getY() = data.getExT break;for(int i = 0 ; i A ; i +) int newX = curPos.getX() + di0; int newY = curPos.getY() + di1;if(data.inArea(newX, newY)& (data.visitednewXn
16、ewY& data.getMaze(newX, newY) = NazeData.R04DX stack.push(new Position(newX, newY);data.visitednewXnewY = true;?for(int i = 0 ; i 4 ; 1 +) int newX = curPos.getX() + di6; int newY = curPos.getY() + di1;if(data.inArea(newX, newY)& !data.visitednewXnewY& data.getMaze(newX, newY) = MazeData./?04D)- sta
17、ck.push(new Position(newX, newY, curPos); data.visitednewXnewY = true;if(lisSolYed)System.out.printin(The maze has no Solution!);setData( x: -1, y: T, isPath: false);private void findPath(Position des)Position cyr = des;while(cur 1=data.result(cur.getX()cue.getY() = true;cur = cur.getPrevO;1617一、工程报
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构与算法-看得见的算法 课程设计报告 数据结构 算法 看得见 课程设计 报告
限制150内