资源简介

在vs2010环境下凸包问题枚举 Graham_scan以及分治三种方法实现,并用matlab将结果画出来,进行验证。细节考虑较全面。

资源截图

代码片段和文件信息

#include 
#include 
#include 
#include 


#include “InitGraph.h“
#include “Convexhull.h“



void printfirst(linkStack P);
void print(linkStack P);
void printOrigin(Vertex *pointint n);
int main()
{
long int startfinish;
int count = 0;
int n;
linkStack P;
P = (linkStack)malloc(sizeof(StackNode));
InitStack(P);
printf(“Input the number of point  n:\n“);
scanf(“%d“&n);
Vertex *point = (Vertex *)malloc(n*sizeof(Vertex));
int choose = 0;
printf(“选择采用哪种执行方式:\n“);
printf(“***************************************************\n“);
printf(“1----基于枚举\n“);
printf(“2----基于Graham-Scan\n“);
printf(“3----基于分治思想\n“);
printf(“0----EXIT\n“);

do
{
scanf(“%d“&choose);
switch(choose)
{
case 1:
GraphInit(pointn);
        printOrigin(pointn);
start = clock();
enumConvexhull(pointP n);
finish = clock();
RunTime[0] =  finish - start;
printf(“显示结果如下:\n“);
         printfirst(P);
printf(“运行时间:%d ms\n“RunTime[0]);
continue;
case 2:
GraphInit(pointn);
        printOrigin(pointn);
start = clock();
Graham_scan(pointPn);
finish = clock();
RunTime[1] = finish - start;
printf(“显示结果如下:\n“);
         print(P);
printf(“运行时间:%d ms\n“RunTime[1]);
continue;
case 3:
GraphInit(pointn);
   /*     FILE  *fid;
fid = fopen(“oooo.txt““r“);
int i;
for(i = 0;i < 14;i++)
{
fscanf(fid“%d“&point[i].x);
fscanf(fid“%d“&point[i].y);
}
point[14].x = 10;
point[14].y = 100;*/

        printOrigin(pointn);
start = clock();
Divide_Graham(pointP0n-1);
finish = clock();
RunTime[2] =  finish - start;

printf(“显示结果如下:\n“);
         print(P);
printf(“运行时间:%d ms\n“RunTime[2]);
continue;
}
}while(choose);

getchar();
return 0;
}

/*****************print**************************/

void print(linkStack L)
{
linkStack P = L;
Vertex result;
ofstream fout2;
fout2.open(“result_pot.txt“);
while(!IsEmpty(P))
{
Pop(P&result);
fout2< printf(“坐标:[%d   %d]\n“result.xresult.y);
}
fout2.close();
}

void printOrigin(Vertex *pointint n)
{
int i;
ofstream fout1;
fout1.open(“original_pot.txt“);
for(i = 0;i < n;i++)
{
printf(“原始点%d  %d\n“point[i].xpoint[i].y);
fout1< }
}

void printfirst(linkStack P)
{
int i;
int k = 0;
Vertex *PP = (Vertex *)malloc(1000*sizeof(Vertex));
while(!IsEmpty(P))
{
Pop(P&PP[k]);
k++;
}
linkStack L = (linkStack)malloc(sizeof(StackNode));
InitStack(L);
Graham_scan(PPLk);
print(L);
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-12-20 11:21  CH3_Test\
     目录           0  2014-12-17 23:59  CH3_Test\CH3_Test\
     文件     8867840  2014-12-20 11:21  CH3_Test\CH3_Test.sdf
     文件         891  2014-12-11 19:21  CH3_Test\CH3_Test.sln
     文件       24576  2014-12-20 11:21  CH3_Test\CH3_Test.suo
     文件        4668  2014-12-14 19:29  CH3_Test\CH3_Test\CH3_Test.vcxproj
     文件        1340  2014-12-11 21:14  CH3_Test\CH3_Test\CH3_Test.vcxproj.filters
     文件         143  2014-12-11 19:21  CH3_Test\CH3_Test\CH3_Test.vcxproj.user
     文件        9958  2014-12-18 15:18  CH3_Test\CH3_Test\Convexhull.h
     目录           0  2014-12-20 08:54  CH3_Test\CH3_Test\Debug\
     文件         381  2014-12-19 21:26  CH3_Test\CH3_Test\Debug\CH3_Test.exe.intermediate.manifest
     文件          49  2014-12-20 08:54  CH3_Test\CH3_Test\Debug\CH3_Test.lastbuildstate
     文件         797  2014-12-20 08:54  CH3_Test\CH3_Test\Debug\CH3_Test.log
     文件         707  2014-12-11 20:08  CH3_Test\CH3_Test\Debug\CH3_Test.vcxprojResolveAssemblyReference.cache
     文件           0  2014-12-11 19:22  CH3_Test\CH3_Test\Debug\CH3_Test.write.1.tlog
     文件        1474  2014-12-19 21:26  CH3_Test\CH3_Test\Debug\cl.command.1.tlog
     文件       11378  2014-12-19 21:26  CH3_Test\CH3_Test\Debug\CL.read.1.tlog
     文件         520  2014-12-19 21:26  CH3_Test\CH3_Test\Debug\CL.write.1.tlog
     文件           2  2014-12-19 21:26  CH3_Test\CH3_Test\Debug\link.10148.read.1.tlog
     文件           2  2014-12-19 21:26  CH3_Test\CH3_Test\Debug\link.10148.write.1.tlog
     文件           2  2014-12-19 21:26  CH3_Test\CH3_Test\Debug\link.11088.read.1.tlog
     文件           2  2014-12-19 21:26  CH3_Test\CH3_Test\Debug\link.11088.write.1.tlog
     文件           2  2014-12-19 21:26  CH3_Test\CH3_Test\Debug\link.13708.read.1.tlog
     文件           2  2014-12-19 21:26  CH3_Test\CH3_Test\Debug\link.13708.write.1.tlog
     文件           2  2014-12-19 21:26  CH3_Test\CH3_Test\Debug\link.1440.read.1.tlog
     文件           2  2014-12-19 21:26  CH3_Test\CH3_Test\Debug\link.1440.write.1.tlog
     文件           2  2014-12-19 21:26  CH3_Test\CH3_Test\Debug\link.2680.read.1.tlog
     文件           2  2014-12-19 21:26  CH3_Test\CH3_Test\Debug\link.2680.write.1.tlog
     文件           2  2014-12-19 21:26  CH3_Test\CH3_Test\Debug\link.3256.read.1.tlog
     文件           2  2014-12-19 21:26  CH3_Test\CH3_Test\Debug\link.3256.write.1.tlog
     文件           2  2014-12-19 21:26  CH3_Test\CH3_Test\Debug\link.3560.read.1.tlog
............此处省略62个文件信息

评论

共有 条评论