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

买了一个域名怎么做网站北京网络优化推广公司

买了一个域名怎么做网站,北京网络优化推广公司,寻找大连网站建设,wordpress 扫码付款1.相关描述 随机生产1000个数字,然后进行冒泡排序与快速排序。随机生成类继承QThread类、冒泡排序使用moveToThread方法添加到一个线程中、快速排序类继承QRunnable类,添加到线程池中进行排序。 2.相关界面 3.相关代码 widget.cpp #include "widget…

1.相关描述

随机生产1000个数字,然后进行冒泡排序与快速排序。随机生成类继承QThread类、冒泡排序使用moveToThread方法添加到一个线程中、快速排序类继承QRunnable类,添加到线程池中进行排序。

 2.相关界面

3.相关代码

widget.cpp

#include "widget.h"
#include "ui_widget.h"
#include "tgeneratenum.h"
#include "tbubblesort.h"
#include "tquicksort.h"
#include <QDebug>
#include <QThreadPool>Widget::Widget(QWidget *parent): QWidget(parent), ui(new Ui::Widget)
{ui->setupUi(this);qDebug() << "主线程:" << QThread::currentThread();/********************  多线程的使用方法一 ****************/TGenerateNum *gen = new TGenerateNum;    // 继承QThread类/******************* 多线程的使用方法二 **********************/QThread *bubbleThread = new QThread;TBubbleSort *bubble = new TBubbleSort;bubble->moveToThread(bubbleThread);/******************* 多线程的使用方法三 线程池的使用 **********************/TQuickSort *quicksort = new TQuickSort;QThreadPool::globalInstance()->setMaxThreadCount(10);// 按钮的信号槽connect(ui->btnStart, &QPushButton::clicked, this, [=](){gen->setCnt(10000);gen->start();});// 生成随机数connect(gen, &TGenerateNum::sendList, this, [=](QVector<int> list){quicksort->setList(list);QThreadPool::globalInstance()->start(quicksort);bubbleThread->start(); // 开启冒泡排序线程for(int i = 0; i < list.size(); i++){ui->listWidgetGenerate->addItem(QString::number(list[i]));}});connect(gen, &TGenerateNum::sendList, bubble, &TBubbleSort::working);connect(bubble, &TBubbleSort::sendList, this, [=](QVector<int> list){for(int i = 0; i < list.size(); i++){ui->listWidgetBubbleSort->addItem(QString::number(list[i]));}});connect(quicksort, &TQuickSort::sendList, this, [=](QVector<int> list){for(int i = 0; i < list.size(); i++){ui->listWidgetQuickSort->addItem(QString::number(list[i]));}});// 释放内存connect(this, &Widget::destroyed, this, [=](){gen->quit();gen->wait();gen->deleteLater();bubbleThread->quit();bubbleThread->wait();bubbleThread->deleteLater();bubble->deleteLater();});
}Widget::~Widget()
{delete ui;
}

生成随机数:

tgeneratenum.h

#ifndef TGENERATENUM_H
#define TGENERATENUM_H#include <QObject>
#include <QThread>class TGenerateNum : public QThread
{Q_OBJECT
public:TGenerateNum(QObject *parent=nullptr);void setCnt(qint32 cnt);// QThread interface
protected:void run() override;
signals:void sendList(QVector<int> list);private:qint32 m_cnt;
};
#endif // TGENERATENUM_H

tgeneratenum.cpp

#include "tgeneratenum.h"
#include <QRandomGenerator>
#include <QVector>
#include <QElapsedTimer>
#include <QDebug>TGenerateNum::TGenerateNum(QObject *parent):QThread(parent) {}void TGenerateNum::setCnt(qint32 cnt)
{m_cnt = cnt;
}void TGenerateNum::run()
{qDebug() << "生成随机数线程地址:" << QThread::currentThread();QElapsedTimer time;time.start();QVector<int> list;for(int i = 0; i < m_cnt; i++){int num = QRandomGenerator::global()->bounded(100000);list.push_back(num);}int milsec = time.elapsed();qDebug() << "生成" << m_cnt << "个随机数总共用时:" << milsec << "毫秒";emit sendList(list);
}

生成随机数,需要加时间种子

冒泡排序:

tbubblesort.h

#ifndef TBUBBLESORT_H
#define TBUBBLESORT_H#include <QObject>class TBubbleSort : public QObject
{Q_OBJECT
public:explicit TBubbleSort(QObject *parent = nullptr);void working(QVector<int> list);
signals:void sendList(QVector<int> list);
private:void bubbleSort(QVector<int>& list);QVector<int> m_list;
};#endif // TBUBBLESORT_H

tbubblesort.cpp

#include "tbubblesort.h"
#include <QElapsedTimer>
#include <QDebug>
#include <QThread>TBubbleSort::TBubbleSort(QObject *parent): QObject{parent}
{}void TBubbleSort::working(QVector<int> list)
{qDebug() << "冒泡线程地址:" << QThread::currentThread();QElapsedTimer time;time.start();this->bubbleSort(list);int milsec = time.elapsed();qDebug() << "冒泡排序总共用时:" << milsec << "毫秒";emit sendList(list);
}void TBubbleSort::bubbleSort(QVector<int> &list)
{for (int i = 0; i < list.size(); i++){for (int j = 1; j < list.size()-i; j++){if (list[j - 1] > list[j]){int temp = list[j - 1];list[j - 1] = list[j];list[j] = temp;}}}
}

快速排序:

tquicksort.h

#ifndef TQUICKSORT_H
#define TQUICKSORT_H#include <QObject>
#include <QRunnable>class TQuickSort : public QObject, public QRunnable
{Q_OBJECT
public:explicit TQuickSort(QObject *parent = nullptr);void setList(QVector<int> list);
signals:void sendList(QVector<int> list);// QRunnable interface
public:void run() override;
private:void quick_sort(QVector<int>& list, int l, int r);QVector<int> m_list;
};#endif // TQUICKSORT_H

tquicksort.cpp

#include "tquicksort.h"
#include <QElapsedTimer>
#include <QDebug>
#include <QThread>
TQuickSort::TQuickSort(QObject *parent): QObject{parent}, QRunnable()
{// 开启自动回收,由线程池回收对象资源setAutoDelete(true);
}void TQuickSort::setList(QVector<int> list)
{m_list = list;
}void TQuickSort::run()
{qDebug() << "快排线程地址:" << QThread::currentThread();QElapsedTimer time;time.start();this->quick_sort(m_list, 0, m_list.size());int milsec = time.elapsed();qDebug() << "快速排序总共用时:" << milsec << "毫秒";emit sendList(m_list);
}void TQuickSort::quick_sort(QVector<int>& list, int l, int r){//如果小于等于1个数据元素·直接返回结束快排函数 r为数组元素总个数if(l+1 >= r){return ;}int first = l, last = r-1, key = list[first];while(first < last){while(first < last && list[last] >= key){--last;}//如果值小于 key分界值 交换list[first] = list[last];while(first < last && list[first] < key){++first;}//如果值大于key分界值 交换list[last] = list[first];}list[first] = key;//递归左右部分进行快排quick_sort(list, l, first);quick_sort(list, first+1, r);
}

http://www.tj-hxxt.cn/news/83275.html

相关文章:

  • 查网站流量查询工具东莞网络营销渠道
  • 张店网站建设价格百度云资源搜索
  • 网站开发策划个人简历google浏览器官网
  • 高端营销型网站制作百度关键词规划师工具
  • 陕西住房和城乡建设厅网站电话app开发费用标准
  • 有哪些网站做的很好东莞网站建设方案外包
  • wordpress双语建站2345浏览器网站进入
  • wordpress issetseo薪酬
  • 如何制作wap网站百度知道推广软件
  • 在线网站创做简历西安市seo排名按天优化
  • 毕业设计做购物网站的要求百度官网首页网址
  • 购物网站设计的意义计算机培训机构
  • 德芙巧克力网站开发方案长沙网站推广公司排名
  • 淘客手机版网站怎么做百度霸屏推广
  • 做电路设计的兼职网站网络营销有哪些例子
  • 在线网站模板ip域名查询地址
  • 网站包括哪些内容吗优化网络推广外包
  • 在互联网公司做网站免费个人网页制作
  • 创意网站建设公司网络做推广广告公司
  • 天蝎网站建设福州外包seo公司
  • 淘宝网站制作公司哪家好营销推广与策划
  • 如何用网页设计制作个人网站企业管理培训视频免费
  • 做网站应该掌握的技术推广方案范例
  • 济南建网站公司报价seo优化网站的手段
  • 短故事网站模板网络营销文案实例
  • eclipse网站开发实例友情链接交换要注意哪些问题
  • wordpress自动添加标签页奉化seo页面优化外包
  • 适配移动网站公司网页制作流程
  • 中文编程做网站google搜索关键词
  • 重庆seo网站怎么创建自己的网站