当前位置:文档之家› 2017年福州大学考研真题-863数据结构与程序设计

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

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; }
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;}
} }
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;}
cout<<w; cout<<endl; } } 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)按照线性探测法构造哈希表(闭散列)。
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: 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++) {
10.写出以下程序的运行结果。 #include <iostream> using namespace std; class A {
public: A ( ) {cout << "A::A ( ) called.\n";} virtual ~A ( ) {cout << "A::A ( ) called.\n";}
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.顺序表用数组实现,在实现插入一个数平均需要移动多少个数?实现删除一个数平均需要移动多少个 数?
} 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 {
17.用 3、5、6、2、4、9 构造二叉搜索树。写出其是 AVL 树时的情况。
五、程序设计题。
18.给定一个十进制位 N,试求其二进制中 1 的个数,算法满足下列复杂度。 (1)时间复杂度为 O(nlogn)。 (2)复杂度只与二进制数中 1 的个数有关。 (3)时间复杂度为 O(1)。
19.快速排序是通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部 分的所有数据都要小,然后在按此方法对这两部分数据 分别进行快速排序,整个排序过程可以递归进行, 以此达到整个数据变成有序序 列。试写出一个快速排序改进算法,使得在最坏情况下,快速排序的时间 复杂度为 O(nlogn)。
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;
福州大学
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++)
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;}
private: int X, Y;
} Point::Point(Point &p) {
X = p.X; Y = p.Y; cout<<"Point 拷贝构造函数调用"<< {
public: Distance (Point xp1, Point xp2); double GetDis ( ) {return dist;}
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 ( ); }
cout<<*(*p+j)<<","; cout<<endl; }
相关主题