64,663
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include "assert.h"
#include "new.h"
#include "stdlib.h"
#include "Stack.h"
using namespace std;
main()
{
Stack::int val;
Stack s1;
// TEST 1
cout << "1: size = " << s1.size()
<< ", capacity = " << s1.capacity() << endl;
// TEST 2
Stack s2(20);
cout << "2: size = " << s2.size()
<< ", capacity = " << s2.capacity() << endl;
// TEST 3
if(!s1.empty() || !s2.empty() || s1.size() != 0 || s2.size())
cout << "3: Logic error" << endl;
// TEST 4
// Intentional overflow
for(Stack::int i = 0; i < Stack::DEF_CAPACITY + 1; i++ )
s1.push(i);
if(!s1.full() || s1.size() != Stack::DEF_CAPACITY)
cout << "4: Logic error" << endl;
// TEST 5
for(Stack::int i = 0; i < 20; i++ )
s2.push(i);
if(!s2.full() || s2.size() != 20)
cout << "5: Logic error" << endl;
// TEST 6
for(int i = Stack::DEF_CAPACITY - 1; i >= 0; i--) {
val = s1.pop();
if(val != i) {
cout << "6: Logic error i = " << i
<< ", val = " << val << endl;
}
}
// TEST 7
val = s1.pop();
if(val != Stack::INVALID_OPERATION || s1.size() != 0)
cout << "7: Logic error" << endl;
// TEST 8
val = s2.pop();
if(val != 19 || s2.size() != 19)
cout << "8: Logic error" << endl;
// TEST 9
val = s2.peek();
if(val != 18 || s2.size() != 19)
cout << "9: Logic error" << endl;
// TEST 10
val = s1.peek();
if(val != Stack::INVALID_OPERATION)
cout << "10: Logic error" << endl;
return 0;
}
class mystack : private stack<int>
{
public:
typedef stack<int> S;
void push(int vaule){ S::push(vaule);}
void pop(){S::pop();}
int top(){return S::top();}
.........
};
#include <iostream>
using namespace std;
class Stack
{
public:
typedef int value_type;
int mi;
};
int main()
{
Stack::value_type i;
}
按照我的理解:
main函数中有:
Stack::int val;
val = s2.pop();
val = s1.peek();
而pop和peek的返回值都是value_type
所以,可以推测val的类型也应该差不多或许maybe是value_type
结论:main函数中的Stack::int val;纯粹是笔误,应该是Stack::value_type