资源简介
要求实现与C 标准库类似的数据结构,包括迭代器等。框架接口在已本仓库中给出,只需要实现`.hpp`文件内所要求的内容即可。
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include “deque.hpp“
#include “exceptions.hpp“
/***************************/
bool need_to_check_throw = 1;
bool good_complexity = 1;//if the complexity is N^2 change to 0
int N = good_complexity ? 50000 : 1000;
/***************************/
class T{
private:
int x;
public:
T(int x):x(x){}
int num()const {return x;}
void change(int y){
x = y;
}
};
bool operator == (const T &a const T &b){
return a.num() == b.num();
}
bool operator != (const T &a const T &b){
return a.num() != b.num();
}
sjtu::deque q;
std::deque stl;
sjtu::deque::iterator it_q;
std::deque::iterator it_stl;
sjtu::deque::const_iterator _it_q;
std::deque::const_iterator _it_stl;
bool equal(){
if(q.size() != stl.size()) return 0;
if(q.empty() != stl.empty()) return 0;
int cnt = 0;
for(it_q = q.begin() it_stl = stl.begin(); it_q != q.end() || it_stl != stl.end(); it_q++ it_stl++){
if(*it_q != *it_stl) {
printf(“cnt = %d\n“cnt);
return 0;
}
cnt++;
}
return 1;
}
void test1(){
printf(“test1: push & pop “);
for(int i=1;i<=N;i++){
if(i % 10 <= 3) q.push_back(T(i)) stl.push_back(T(i));else
if(i % 10 <= 7) q.push_front(T(i)) stl.push_front(T(i));else
if(i % 10 <= 8) q.pop_back() stl.pop_back();else
if(i % 10 <= 9) q.pop_front() stl.pop_front();
}
if(!equal()){puts(“Wrong Answer“);return;}
while (!q.empty()){
q.pop_back();
stl.pop_back();
}
puts(“Accept“);
}
void test2(){
printf(“test2: at & [] & front & back “);
int flag = 0;
try{
int t = q.front().num();
}catch(...){flag ++;}
try{
int t = q.back().num();
}catch(...){flag ++;}
if(flag != 2 && need_to_check_throw){puts(“Wrong Answer“);return;}
for(int i=1;i<=N;i++){
if(i % 10 <= 3) q.push_back(T(i)) stl.push_back(T(i));else
if(i % 10 <= 7) q.push_front(T(i)) stl.push_front(T(i));else
if(i % 10 <= 8) q.pop_back() stl.pop_back();else
if(i % 10 <= 9) q.pop_front() stl.pop_front();
}
flag = 0;
try{
int t = (q.at(q.size() + 100)).num();
}catch(...){flag = 1;}
if(flag != 1 && need_to_check_throw){puts(“Wrong Answer“);return;}
int num = q.size();
for(int i=0;i<100;i++)
{
int t = rand() % num;
if(q[t] != stl[t] || q.at(t) != stl.at(t)){puts(“Wrong Answer“);return;}
}
if(q.front() != stl.front() || q.back() != stl.back()){puts(“Wrong Answer“);return;}
puts(“Accept“);
}
void test3(){
printf(“test3: itetator operation “);
int num = q.size();
for(int i =1 ; i <= 1000; i++)
{
int t1 = rand() % num;
int t2 = rand() % num;
if(*(q.begin() + t1) != *(stl.begin() + t1)){puts(“Wrong Answer“);return;}
if(t2 && *(q.end() - t2) != *(stl.end() - t2)){puts(“Wrong Answer“);return;}
if((q.begin() + t1) - (q.begin() + t2) != (t1 - t2)){puts(“Wrong Answer“);return;}
}
if((q.begin() + num) != q.end()) {puts(“Wrong Answer“);return;}
if((q.end() - num) != q.begin()) {put
相关资源
- STM32 BLDC 无刷电机
- C语言实现 设备信息管理系统
- 基于VSCode和CMake实现C++开发
-
Google C++ st
yle Guide - stm8l四按键状态机实现
- stm32 实现Fatfs对U盘文件操作(main.c)
- QR二维码C++源码 算法实现
- stm32f103 USB键盘
- C++ Primer by Stanley B. Lippman Josée La
- 链表实现学生管理系统(main.c)
- 银行家算法分配资源的模拟实现(m
- OBD_CAN读取代码(stm32f103)
-
STM32-ba
se64加密源代码 - C语言编译器的设计与实现.doc
- stm32 MQTT
- stm32f103 can驱动
- STM32三菱PLC源码原理图
- STM8S105C6例程
- 2048小游戏c语言实现
- 转 VC++ 实现电子邮件(Email)发送
- 使用 IBM Rational Systems Developer 和 Rati
- 23种设计模式(C++实现版本
- VC++6.0番茄西红柿VAXvirsual assist X完美破
- 扫描线多边形填充算法实现
- Microsoft Visual C++ 2005 Redistributable Pack
- 可靠性试验数据处理方法与工程实现
- c++实现的文件上传服务器
- 一个C++实现的源代码行数统计工具
- 水晶报表Crystal Reports运行环境CRRunti
- 利用C++类实现PNG图像读写及显示
评论
共有 条评论