#include <iostream>
using namespace std;
class Entry {
public:
Entry* next;
int data;
//**********found**********
Entry(Entry* n, int d) : _______________________, data(d) { }
};
class Stack {
Entry* top;
public:
Stack() : top(0) { }
~Stack()
{
while (top != 0)
{
Entry* tmp = top;
//**********found**********
top = _______________________;
delete tmp;
}
}
void push(int data)
{
//**********found**********
top = new Entry(_______________________, data);
}
int pop()
{
if (top == 0) return 0;
//**********found**********
int result = _______________________;
top = top->next;
return result;
}
};
int main()
{
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Stack s;
int i = 0;
for (i = 0; i < 10; i++) {
cout << a[i] << ' ';
s.push(a[i]);
}
cout << endl;
for (i = 0; i < 10; i++) {
cout << s.pop() << ' ';
}
cout << endl;
return 0;
}
参考答案:
(1)next(n)
(2)top->next
(3)top
(4)top->data
考点分析】
本题考查的是Entry类和Stack类其中涉及指针,构造函数析构函数,成员函数。【解题思路】
(1)主要考查考生对构造函数的掌握情况,使用成员列表初始化。
(2)主要考查考生对栈的掌握情况.新元素需要添加到栈页。
(3)主要考查考生对动态分配的掌握情况.给栈顶添加元素。
(4)主要考查考生对栈的掌握情况推出栈顶元素。