阅读下列C++程序和程序说明,将应填入(n)处的字句写在对应栏内。【说明】[程序6说明]单源最短路径的分支限界算法。const int MAXNUM=29999;include<iostream>include<vector>include<algorithm>include<functional>using namespace std;template <class VertexType,class EdgeType>class MinNode { //程序中使用的最小化堆的结点说明friend class Graph<VertexType,EdgeType>public:MinNode (int nl, EdgeType length1){ VexNum=nl;length=length1;}bool operator>(const MinNode<VertexType,EdgeType>p)const{ return (1)>p.length;}private:int VexNum;//记录源点序号,序号数组p及distance下标相一致。源点为初始扩展顶点EdgeType length;//记录源点到本顶点的当前最短路径的长度,源点到自身的长度为0}template<class VertexType,classEdgeType>void Graph<VertexType,EdgeType>:: shortestpath(VertexType start) {int j,k,source;//source 记录源点的序号。EdgeType*distance=(2);int*p=new int[MaxNumVertex];vector<MinNode<VertexType,EdgeType> >H;for(source=0;source<MaxNumVertex;source++){ if(NodeList[source]==start)break;}if (source>=MaxNumVertex){cout<<”This is error!”<<end1;return;}MinNode<VertexType,Edge Type>(3);for(k=0;k<MaxNumVertex;k++){ distance[k]:MAXXUM; //记录源点到本顶点k的最终的最短路径的长度p[k]=source; //记录最短路径上的本顶点的直接前驱顶点的序号}distance[source]=0;p[source]=-1;//m 是源点,前一顶点不存在vector<MinNode<VertexType, EdgeType>>::iterator q;while(1){for(j=0;j<MaxNumVertex;j++)if((AdjMatrix[E.VexNum* MaxNumVertex+j]<MAXNUM)((4)<distance[j])){ distance[j]=E.length+AdjMatrix[E.VexNum* MaxNumVertex+j];p[j]=E. VexNum; //记录顶点j的前一顶点MinNode<VertexType, EdgeType>(5);H.push_ back(N);push_heap(H. begin(),H.end(),greater<MinNode<VertexType,EdgeType>>());}if(H.empty()=true)break; //若优先队列为空,那么算法结束else{pop_ heap(H.begin(),H. end(),greater<MinNode<VertexType,EdgeType>>());q=H.end()-1; //从最小化堆中取路径最短的顶点E=*q;H.pop_ back(); //删除从最小化堆中“挤”出的顶点}} //end whilefor(k=0;k<MaxNumVertex;k++){cout<<"Shorstest path from vertex"<<k<<"is"<<distance[k]<<end1;j=k;cou

阅读下列C++程序和程序说明,将应填入(n)处的字句写在对应栏内。

【说明】[程序6说明]单源最短路径的分支限界算法。

const int MAXNUM=29999;

include<iostream>

include<vector>

include<algorithm>

include<functional>

using namespace std;

template <class VertexType,class EdgeType>

class MinNode { //程序中使用的最小化堆的结点说明

friend class Graph<VertexType,EdgeType>

public:

MinNode (int nl, EdgeType length1)

{ VexNum=nl;

length=length1;

}

bool operator>(const MinNode<VertexType,EdgeType>&p)const

{ return (1)>p.length;

}

private:

int VexNum;

//记录源点序号,序号数组p及distance下标相一致。源点为初始扩展顶点

EdgeType length;

//记录源点到本顶点的当前最短路径的长度,源点到自身的长度为0

}

template<class VertexType,classEdgeType>

void Graph<VertexType,EdgeType>:: shortestpath(VertexType start) {

int j,k,source;//source 记录源点的序号。

EdgeType*distance=(2);

int*p=new int[MaxNumVertex];

vector<MinNode<VertexType,EdgeType> >H;

for(source=0;source<MaxNumVertex;source++)

{ if(NodeList[source]==start)break;}

if (source>=MaxNumVertex){cout<<”This is error!”<<end1;return;}

MinNode<VertexType,Edge Type>(3);

for(k=0;k<MaxNumVertex;k++)

{ distance[k]:MAXXUM; //记录源点到本顶点k的最终的最短路径的长度

p[k]=source; //记录最短路径上的本顶点的直接前驱顶点的序号

}

distance[source]=0;p[source]=-1;//m 是源点,前一顶点不存在

vector<MinNode<VertexType, EdgeType>>::iterator q;

while(1){

for(j=0;j<MaxNumVertex;j++)

if((AdjMatrix[E.VexNum* MaxNumVertex+j]<MAXNUM)

&&((4)<distance[j]))

{ distance[j]=E.length+AdjMatrix[E.VexNum* MaxNumVertex+j];

p[j]=E. VexNum; //记录顶点j的前一顶点

MinNode<VertexType, EdgeType>(5);

H.push_ back(N);

push_heap(H. begin(),H.end(),greater<MinNode<VertexType,

EdgeType>>());

}

if(H.empty()=true)break; //若优先队列为空,那么算法结束

else{

pop_ heap(H.begin(),H. end(),greater<MinNode<VertexType,

EdgeType>>());

q=H.end()-1; //从最小化堆中取路径最短的顶点

E=*q;

H.pop_ back(); //删除从最小化堆中“挤”出的顶点

}

} //end while

for(k=0;k<MaxNumVertex;k++){

cout<<"Shorstest path from vertex"<<k<<"is"<<distance[k]<<end1;

j=k;cou


相关考题:

阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【C++程序】include include 阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【C++程序】include < stdio. h >include < string. h >define Max 1000class Bank{int index;char date [Max] [10]; // 记录交易日iht amount[Max]; // 记录每次交易金额,以符号区分存钱和取钱int rest[ Max]; // 记录每次交易后余额static iht sum; // 账户累计余额public:Bank( ) {index =0;}void deposit( char d[ ] , int m) //存入交易{strcpy ( date [ index ], d);amount[ index] = m;(1);rest[ index] = sum;index++;}void withdraw (char d[ ], int m) //取出交易{strcpy( date[ index] ,d);(2);(3);rest[ index] = sum;index++;}void display( );};int Bank:: sum = 0;void Bank:: display ( ) //输出流水{int i;printf("日期 存入 取出 余额\n");for (4){printf(" %8s" ,date[i] );if (5)printf(" %6d" , -amount[i] );elseprintf( "%6d ",amount[i] );printf( "% 6d\n" ,rest[i] );} }void main( ){Bank object;object. deposit ( "2006.2.5", 1 00 );object. deposit( "2006.3.2" , 200);object. withdraw( "2006.4.1", 50);object. withdraw( "2006.4.5", 80);object. display ( );}本程序的执行结果如下:日期 存入 取出 余额 2006.2.5 100 1002006.3.2 200 3002006.4.1 50 2502006.4.5 80 170

阅读以下说明和流程图,将应填入(n)处的字句写在对应栏内。【说明】已知头指针分别为La和lb的有序单链表,其数据元素都是按值非递减排列。现要归并La和Lb得到单链表Lc,使得Lc中的元素按值非递减排列。程序流程图如下所示:

阅读以下说明及Visual Basic程序代码,将应填入(n)处的字句写在对应栏内。【说明】以下程序为求行列式X(5,5)的值S。【Visual Basic代码】Private Function col ( byval x ( 5,5 ) as integer ) as longdim fesult as longdim temp as longdim I as integerdim j as integerdim k as imegerresult = 0for I = to 5(1)for j = 1 to 5if I+j>6 thenk= ( 1+j ) mod 5elsek=1endiftemp=temp*x ( k,j )(2)result=(3)(4)(5)End function

阅读以下说明,以及用C++在开发过程中所编写的程序代码,将应填入(n)处的字句写在对应栏内。【说明】在下面函数横线处填上适当的字句,使其输出结果为:构造函数.构造函数.1,25,6析构函数析构函数.【C++代码】include "iostream.h"class AA{ public;AA(int i,int j){A=i; B=j;cout<<"构造函数.\n";}~AA(){(1);}void print();private:int A, B;};void AA∷print(){cout<<A<<","<<B<<endl;}void main(){AA *a1, *a2;(2)=new AA(1, 2);a2=new AA(5, 6);(3);a2->print();(4) a1;(5) a2;}

阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写在对应栏内。【说明】阅读下面几段C++程序回答相应问题。比较下面两段程序的优缺点。①for (i=0; i<N; i++ ){if (condition)//DoSomething…else//DoOtherthing…}②if (condition) {for (i =0; i<N; i++ )//DoSomething}else {for (i=0; i <N; i++ )//DoOtherthing…}

阅读下列程序说明和C程序,将应填入(n)处的字句写在对应栏内。[函数2.1说明]下面程序的功能是计算x和y的最小公倍数。[函数2.1]main(){ int m,n,d,r;seanf("%d %d",m,n);if(m<n) {r=m;m=n;n=r;}(1);while (d%n! =0) (2);printf("%d\n",d);}[函数2.2说明]下述程序接收键盘输入,直到句点“.”时结束。输入的字符被原样输出,但连续的空格输入将转换成一个空格。[函数2.2]include <stdio.h>main(){ char c,preChar='\0';c = getchar();while(c! = '.'){if((3)) putchar(c);else if(preChar! =' ') putchar(c);(4);c=(5);}}

●试题二阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】该程序运行后,输出下面的数字金字塔【程序】includestdio.hmain (){char max,next;int i;for(max=′1′;max=′9′;max++){for(i=1;i=20- (1) ;++i)printf(" ");for(next= (2) ;next= (3) ;next++)printf("%c",next);for(next= (4) ;next= (5) ;next--)printf("%c",next);printf("\n");}}

试题三(共 15 分)阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。

阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。【C++代码】 #include using namespace std; class invoice{ public: (1){ cout

阅读下列说明和?C++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】阅读下列说明和?Java代码,将应填入?(n)?处的字句写在答题纸的对应栏内。【说明】某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种类可能不同,但其制作过程相同。前台服务员?(Waiter)?调度厨师制作套餐。现采用生成器?(Builder)?模式实现制作过程,得到如图?6-1?所示的类图。