当前位置: 首页 > news >正文

互动网站设计wordpress安装在本地安装

互动网站设计,wordpress安装在本地安装,网站搭建上门多少钱,后台管理系统界面C数据结构与算法 目录 队列介绍 队列这种容器,就像大家排队上公交车一样。 第一个来到的人排在最前面; 最后来的排在最后面; 第一个先上车(离开队列); 队列的接口 队列是有如下接口的容器&#xff1…

C++数据结构与算法 目录

队列介绍

队列这种容器,就像大家排队上公交车一样。

第一个来到的人排在最前面;

最后来的排在最后面;

第一个先上车(离开队列);

队列的接口

队列是有如下接口的容器:

class Queue
{
public:const int& first(void) const;//队列的对头(第一个元素),最先进队列的元素inline bool empty(void) const;//判断队列里是否没有元素(空队列)inline size_t size(void) const;//返回队列元素数量void enqueue(const int& item);//将元素item进队列void dequeue(void);//将对头(队列的第一个元素)出队列(从队列中删除)void clear(void);//清空队列中的所有元素

实现思路

由于双链表的接口覆盖了队列的接口,所以可以使用双链表来实现一个队列。

这样就可以在双链表外面封装出一个队列的类。

在实现的时候,队列的接口只需要调用双链表的接口即可。

题目如下

#include <iostream>
#include <iomanip>
#include <list>
using namespace std;//------下面的代码是用来测试你的代码有没有问题的辅助代码,你无需关注------
#include <algorithm>
#include <cstdlib>
#include <iostream> 
#include <vector>
#include <utility>
using namespace std;
struct Record { Record(void* ptr1, size_t count1, const char* location1, int line1, bool is) :ptr(ptr1), count(count1), line(line1), is_array(is) { int i = 0; while ((location[i] = location1[i]) && i < 100) { ++i; } }void* ptr; size_t count; char location[100] = { 0 }; int line; bool is_array = false; bool not_use_right_delete = false; }; bool operator==(const Record& lhs, const Record& rhs) { return lhs.ptr == rhs.ptr; }std::vector<Record> myAllocStatistic; void* newFunctionImpl(std::size_t sz, char const* file, int line, bool is) { void* ptr = std::malloc(sz); myAllocStatistic.push_back({ ptr,sz, file, line , is }); return ptr; }void* operator new(std::size_t sz, char const* file, int line) { return newFunctionImpl(sz, file, line, false); }void* operator new [](std::size_t sz, char const* file, int line)
{return newFunctionImpl(sz, file, line, true);
}void operator delete(void* ptr) noexcept { Record item{ ptr, 0, "", 0, false }; auto itr = std::find(myAllocStatistic.begin(), myAllocStatistic.end(), item); if (itr != myAllocStatistic.end()) { auto ind = std::distance(myAllocStatistic.begin(), itr); myAllocStatistic[ind].ptr = nullptr; if (itr->is_array) { myAllocStatistic[ind].not_use_right_delete = true; } else { myAllocStatistic[ind].count = 0; }std::free(ptr); } }void operator delete[](void* ptr) noexcept { Record item{ ptr, 0, "", 0, true }; auto itr = std::find(myAllocStatistic.begin(), myAllocStatistic.end(), item); if (itr != myAllocStatistic.end()) { auto ind = std::distance(myAllocStatistic.begin(), itr); myAllocStatistic[ind].ptr = nullptr; if (!itr->is_array) { myAllocStatistic[ind].not_use_right_delete = true; } else { myAllocStatistic[ind].count = 0; }std::free(ptr); } }
#define new new(__FILE__, __LINE__)
struct MyStruct { void ReportMemoryLeak() { std::cout << "Memory leak report: " << std::endl; bool leak = false; for (auto& i : myAllocStatistic) { if (i.count != 0) { leak = true; std::cout << "leak count " << i.count << " Byte" << ", file " << i.location << ", line " << i.line; if (i.not_use_right_delete) { cout << ", not use right delete. "; }	cout << std::endl; } }if (!leak) { cout << "No memory leak." << endl; } }~MyStruct() { ReportMemoryLeak(); } }; static MyStruct my; void check_do(bool b, int line = __LINE__) { if (b) { cout << "line:" << line << " Pass" << endl; } else { cout << "line:" << line << " Ohh! not passed!!!!!!!!!!!!!!!!!!!!!!!!!!!" << " " << endl; exit(0); } }
#define check(msg)  check_do(msg, __LINE__);
//------上面的代码是用来测试你的代码有没有问题的辅助代码,你无需关注------class Queue
{
public:inline const int& first(void) const;inline bool empty(void) const;inline size_t size(void) const;void enqueue(const int& _item);void dequeue(void);void clear(void);
private://使用双链表实现队列std::list<int> m_queue;
};inline const int& Queue::first(void) const
{int a = 0;return a;
}bool Queue::empty(void) const
{return false;
}void Queue::clear(void)
{
}size_t Queue::size(void) const
{return -1;
}void Queue::enqueue(const int& _item)
{
}void Queue::dequeue(void)
{
}int main(int argc, char** argv)
{//test clear{Queue s;check(s.size() == 0);check(s.empty());s.enqueue(1);check(s.size() == 1);check(s.empty() == false);s.clear();check(s.size() == 0);check(s.empty());}//test first{Queue q;check(q.size() == 0);q.enqueue(1);check(q.size() == 1);auto q2 = q;check(q2.size() == 1);q = q2;q.enqueue(2);auto first = q2.first();check(first == 1);check(q.size() == 2);check(q.first() == 1);q.clear();check(q.size() == 0 && q.empty());}//test enqueue dequeue{Queue q;for (size_t i = 0; i < 10; i++){q.enqueue(i);}int i = 0;while (!q.empty()){check(q.first() == i++)q.dequeue();}check(q.size() == 0 && q.empty());}
}

预期输出如下

line:71 Pass
line:72 Pass
line:74 Pass
line:75 Pass
line:77 Pass
line:78 Pass
line:83 Pass
line:85 Pass
line:87 Pass
line:91 Pass
line:92 Pass
line:93 Pass
line:95 Pass
line:107 Pass
line:107 Pass
line:107 Pass
line:107 Pass
line:107 Pass
line:107 Pass
line:107 Pass
line:107 Pass
line:107 Pass
line:107 Pass
line:110 Pass
Memory leak report:
No memory leak.
http://www.yayakq.cn/news/604666/

相关文章:

  • 求个网站2020急急急胶州建网站
  • 云南建网站做消费金融网站价格
  • 滁州网站建设工作室h5链接是什么意思
  • 湛江网站设计哪家好二手域名
  • 快速网站如何做国外的电商网站
  • 百度头条怎么做网站公众号开发教程零基础
  • 手机怎样做自己的网站无锡企业网站的建设
  • 湖北鼎天宏图建设工程有限公司网站东道品牌创意集团
  • 如何分析对手网站关键词网站utf8乱码
  • 湖北建设银行网站首页行业门户网站是什么
  • .net给网站做短信验证网站首页logo怎么修改
  • 网站引导页一般是什么格式网站如何接入支付宝
  • 企业网站报备网站备案 拍照网点
  • app网站建设介绍上海网站seo设计
  • 北京企业网站优化过年做那些网站致富
  • joomla适合做什么网站公司规模介绍范文
  • 免费推广网站地址大全网站如何提升用户体验
  • 网站开发脚本语言opencms wordpress
  • 网站建设犀牛云怎么玩互联网能赚钱
  • 可以直接打开网站的网页手机移动端网站
  • 杭州优化网站查企业网站有哪些
  • 网络编辑的网站建设题网站建设功能分为几种
  • 建站公司平台主机屋网站在那注册
  • 平阳网站优化福州企业网站建设专业服务
  • 长春火车站在哪联通公司网站谁做的
  • 网站维护托管要多少钱深圳龙华街道三联社区
  • 博客网站主页代码html网站推广沈阳
  • 自己网站如何做关键词排名提供郑州网站建设
  • 用flash做的网站欣赏制作网页首页教程
  • 网站制作公司兴田德润实力强wordpress指定分类主动推送百度