最短路径流程图和算法

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

算法流程图

扫描程序

#include

#include

#define NETWORK_ERROR -1

#define NETWORK_OK 0

#define PORT_MIN 1

#define PORT_MAX 65535

HANDLE hThread;

DWORD hID;

char hostname[30];

int starting_port = 0; 将节点放入优先队列 从优先队列中取出当前最优元素并算出当前这个可行解的路径长度和耗费并与最优解比较 不如下界? 选择头节点 Y

将这个节点保存下来作为剪枝使用的下界

队列为空? Y 分析当前的下界,得出程序结果,并返回. N 利用Dijkstra 算法算出出租车到各个等候地点的最短路径以及最小耗费 N

int ending_port = 0;

int nopen = 0;

DWORD portscan();

int main(){

int ret;

WSADATA dat;

DWORD version;

version = MAKEWORD(2,2);

ret = WSAStartup(version,&dat);

if(ret != 0){

printf("Error initializing Winsock.\n"); WSACleanup();

return NETWORK_ERROR;

}

if(ret == 0){

printf("Enter hostname:");

scanf("%s",hostname);

printf("Enter starting port:");

scanf("%d",&starting_port);

if(starting_port < PORT_MIN){

printf("Invalid port number.\n"); WSACleanup();

return NETWORK_ERROR;

}

printf("Enter ending port:");

scanf("%d",&ending_port);

if(ending_port > PORT_MAX){

printf("Invalid port number.\n"); WSACleanup();

return NETWORK_ERROR;

}

printf("\nScanning [%s]...\n",hostname);

hThread = CreateThread(0,0,(LPTHREAD_START_ROUTINE)portscan,0,0,&hID);

if(hThread == 0){

printf("Failed to create thread.\n");

WSACleanup();

return NETWORK_ERROR;

}

sleep(-1);

}

WSACleanup();

return NETWORK_OK;

}

DWORD portscan(){

int i,nret;

SOCKET thesocket;

LPHOSTENT hostent;

thesocket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);

hostent = gethostbyname((hostname));

for(i = starting_port;i < ending_port+1;++i){

SOCKADDR_IN hostinfo;

hostinfo.sin_family = AF_INET;

hostinfo.sin_addr=*((LPIN_ADDR)*hostent->h_addr_list);

hostinfo.sin_port = htons(i);

nret = connect(thesocket,(LPSOCKADDR)&hostinfo,sizeof(hostinfo));

if(nret == 0){

printf("\n\t%d\n",i);

++nopen;

}

}

printf("\nScan complete.\n\n");

printf("Number of ports opened = %d\n",nopen);

closesocket(thesocket);

}

相关文档
最新文档