2017年福州大学考研真题-863数据结构与程序设计

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
} }
9.写出以下程序的运行结果。 #include <iostream.h> #include <math.h> using namespace std; class Point {
public: Point (int xx =0, int yy = 0) { X = xx; Y = yy; cout<<"构造函数被调用"<<endl; } Point(Point &p); int GetX ( ) {return X;} int GetY ( ) {return Y;}
17.用 3、5、6、2、4、9 构造二叉搜索树。写出其是 AVL 树时的情况。
五、程序设计题。
18.给定一个十进制位 N,试求其二进制中 1 的个数,算法满足下列复杂度。 (1)时间复杂度为 O(nlogn)。 (2)复杂度只与二进制数中 1 的个数有关。 (3)时间复杂度为 O(1)。
19.快速排序是通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部 分的所有数据都要小,然后在按此方法对这两部分数据 分别进行快速排序,整个排序过程可以递归进行, 以此达到整个数据变成有序序 列。试写出一个快速排序改进算法,使得在最坏情况下,快速排序的时间 复杂度为 O(nlogn)。
private: int X, Y;
} Point::Point(Point &p) {
X = p.X; Y = p.Y; cout<<"Point 拷贝构造函数调用"<<endl;
} class Distance {
public: Distance (Point xp1, Point xp2); double GetDis ( ) {return dist;}
public: void g ( ) {cout<<"Call C's function g ( )"<<endl;}
} int main ( ) {
C cc; cc.B::f ( ); cc.B::g ( ); cc.g ( ); return 0; }
四、算法计算题。
11.顺序表用数组实现,在实现插入一个数平均需要移动多少个数?实现删除一个数平均需要移动多少个 数?
for (k=j; k>0; k--) cout<<"*";
cout<<endl; } }
4.写出以下程序的运行结果。 #include <iostream> using namespace std; void main ( ) {
int Array[3]; Array[0] = 10; Array[l] = 20; Array[2] = 30; int *pArray; pArray = &Array[0]; cout<<"pArray points to the value."<<endl; cout<<*pArray<<endl; cout<<*(pArray+1)<<endl; }
} class B {
public: void f ( ) {cout<<"Call B's function f ( )"<<endl;} void g ( ) {cout<<"Call B's function g ( )"<<endl;};
} class C:public A, public B {
6.写出以下程序的运行结果。 #include <iostream>
using namespace std; fun ( ); fun ( ); void main ( ) {
fun ( ); fun ( ); } void fun ( ) { static int a = l; int i = 5; a++; i++; cout<<"i="<<i<<",a="<<a<<endl; }
cout<<*(*p+j)<<","; cout<<endl; }
2.写出以下程序的运行结果。 #include <iostream> using namespace std; void print (int w) {
int i; if (w != 0) {
print(w-1); for (i=l; i<=w; i++)
cout<<w; cout<<Baidu Nhomakorabeandl; } } void main ( ) { print(4); }
3.写出以下程序的运行结果 #include <iostream> using namespace std; void main ( ) {
int j, k; for (j=5; j>0; j--) {
12.写出所有 ABC 为入栈序列的可能的出栈序列。
13.给定数列 5、3、6、8、2、9、7、4。根据给定数列写出插入排序前四趟的过程。
14.将 23、15、27、31、8、5、18 初始化为极小化堆并执行两次 DeleteMin 操作。
15.用 kruskal 算法对下图构造最小支撑树。
16.设散列函数 H(k)=kmod7,散列表的地址空间为 0-6,对关键字序列{32, 13, 49, 18, 22, 38, 21}。 (1)按链地址法处理冲突的办法构造哈希表(开散列)。 (2)按照线性探测法构造哈希表(闭散列)。
7.写出以下程序的运行结果。 #include <iostream> using namespace std; class Point {
public: Point (int xx=0, int yy = 0) {X = xx; Y = yy; countP++;} int GetX ( ) {return X;} int GetY ( ) {return Y;} void GetC ( ) {cout<<"Object id="<<countP<<endl;}
int main ( ) { A *a = new B(15);
delete a; return 0; }
11.写出以下程序的运行结果。 #include <iostream> using namespace std; class A {
public: void f ( ) {cout<<"Call A's function f ( )"<<endl;}
private: Point p1, p2; double dist;
}; Distance::Distance (Point xp1, Point xp2) : p1(xp1), p2(xp2) {
cout<<"Distance 构造函数调用"<<endl; double x = double (p1.GetX ( ) - p2.GetX ( )); double y = double (p1.GetY ( ) - p2.GetY ( )); dist = sqrt (x*x + y*y); } void main ( ) { Point myp1 (1, 1), myp2 (4, 5); Distance myd (myp1, myp2); cout<<"The distance is:"; cout<<"myd.GetDis ( )"<<endl; }
for (j=0; j<4; j++) cout<<*(*(p+i)+j)<<" ";
cout<<endl; } for (i=0; i<20; i++)
for (i=0; i<2; i++) { for (j=3; j>=0; j--) cout<<p[i][j]<<" "; cout<<endl;
20.M*N 方格中,有些方格做了标记,标记过的方格不能走,要求各个线路不能重叠,确定 a 到 b 的最近 距离。
5.写出以下程序的运行结果。
#include <iostream> using namespace std; int i = 4; void main ( ) {
cout<<"i="<<i<<endl; i = 5; {
int i; i = 7; cout<<"i="<<i<<endl; } cout<<"i="<<i; }
10.写出以下程序的运行结果。 #include <iostream> using namespace std; class A {
public: A ( ) {cout << "A::A ( ) called.\n";} virtual ~A ( ) {cout << "A::A ( ) called.\n";}
}; class B: pubilc A {
public: B(int i) {cout << "B::B ( ) called.\n"; buf = new char[i];} virtual ~B ( ) {delete []buf; cout<<"B::B ( ) called.\n";}
private: char *buf;
8.写出以下程序的运行结果。 #include <iostream>
using namespace std; void main ( ) {
int b[2][4] = {12, 36, 62, 14, 56, 98, 74, 63}; int (*p)[4] = b; int i, j; for (i=0; i<2; i++) {
private: int X, Y; static int countP;
}; int Point::countP = 0; void main ( ) {
Point A(4, 5); cout<<"Point A,"<<A.GetX ( )<<","<<A.GetY ( ); A.GetC ( ); cout<<"Point B,"<<B.GetX ( )<<","<<B.GetY ( ); B.GetC ( ); }
福州大学
2017 年招收攻读硕士学位研究生入学考试
863 数据结构与程序设计
一、程序阅读题(每小题 4 分,共计 48 分)。
1.写出以下程序的运行结果。 #include <iostream> using namespace std; void main ( ) {
int b[3][5] = {11, 2, 13, 14, 15, 21, 22, 23, 24, 25, 31, 32, 33, 34, 35}; int (*p)[5]; p = b; for (int j=0; j<5; j++)
相关文档
最新文档