├── 01sort可执行文件.zip ├── 02subway可执行文件.zip ├── 1850009_一二三_计算机科学与技术_源代码 ├── 01_sort │ ├── 01_sort.pro │ ├── 01_sort.pro.user │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ ├── mainwindow.ui │ ├── re_dialog.cpp │ ├── re_dialog.h │ ├── re_dialog.ui │ ├── subwindow.cpp │ ├── subwindow.h │ └── subwindow.ui └── 02_subway │ ├── 02_subway.pro │ ├── 02_subway.pro.user │ ├── add_sta.cpp │ ├── add_sta.h │ ├── add_sta.ui │ ├── add_way.cpp │ ├── add_way.h │ ├── add_way.ui │ ├── error.cpp │ ├── error.h │ ├── error.ui │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ ├── mainwindow.ui │ └── station.h ├── 1850009_一二三_计算机科学与技术_设计说明书.doc ├── readme.txt └── 《数据结构》课程设计计划及题目2020—给学生件.doc /01sort可执行文件.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trigady/Array-sorting-display-and-Shanghai-Metro-Line-Planning/99fd27edf708443bf0e87304a951c1966f075276/01sort可执行文件.zip -------------------------------------------------------------------------------- /02subway可执行文件.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trigady/Array-sorting-display-and-Shanghai-Metro-Line-Planning/99fd27edf708443bf0e87304a951c1966f075276/02subway可执行文件.zip -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/01_sort/01_sort.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | main.cpp \ 20 | mainwindow.cpp \ 21 | re_dialog.cpp \ 22 | subwindow.cpp 23 | 24 | HEADERS += \ 25 | mainwindow.h \ 26 | re_dialog.h \ 27 | subwindow.h 28 | 29 | FORMS += \ 30 | mainwindow.ui \ 31 | re_dialog.ui \ 32 | subwindow.ui 33 | 34 | CONFIG += c++11 35 | 36 | # Default rules for deployment. 37 | qnx: target.path = /tmp/$${TARGET}/bin 38 | else: unix:!android: target.path = /opt/$${TARGET}/bin 39 | !isEmpty(target.path): INSTALLS += target 40 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/01_sort/01_sort.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {7b6b20ad-47af-446b-aa4f-d8c02f64e52a} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 1 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | -fno-delayed-template-parsing 60 | 61 | true 62 | 63 | 64 | 65 | ProjectExplorer.Project.Target.0 66 | 67 | Desktop Qt 5.14.2 MSVC2017 64bit 68 | Desktop Qt 5.14.2 MSVC2017 64bit 69 | qt.qt5.5142.win64_msvc2017_64_kit 70 | 1 71 | 0 72 | 0 73 | 74 | C:/Users/www/Desktop/build-01_sort-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug 75 | 76 | 77 | true 78 | QtProjectManager.QMakeBuildStep 79 | true 80 | 81 | false 82 | false 83 | false 84 | 85 | 86 | true 87 | Qt4ProjectManager.MakeStep 88 | 89 | false 90 | 91 | 92 | false 93 | 94 | 2 95 | Build 96 | Build 97 | ProjectExplorer.BuildSteps.Build 98 | 99 | 100 | 101 | true 102 | Qt4ProjectManager.MakeStep 103 | 104 | true 105 | clean 106 | 107 | false 108 | 109 | 1 110 | Clean 111 | Clean 112 | ProjectExplorer.BuildSteps.Clean 113 | 114 | 2 115 | false 116 | 117 | Debug 118 | Qt4ProjectManager.Qt4BuildConfiguration 119 | 2 120 | 121 | 122 | C:/Users/www/Desktop/build-01_sort-Desktop_Qt_5_14_2_MSVC2017_64bit-Release 123 | 124 | 125 | true 126 | QtProjectManager.QMakeBuildStep 127 | false 128 | 129 | false 130 | false 131 | true 132 | 133 | 134 | true 135 | Qt4ProjectManager.MakeStep 136 | 137 | false 138 | 139 | 140 | false 141 | 142 | 2 143 | Build 144 | Build 145 | ProjectExplorer.BuildSteps.Build 146 | 147 | 148 | 149 | true 150 | Qt4ProjectManager.MakeStep 151 | 152 | true 153 | clean 154 | 155 | false 156 | 157 | 1 158 | Clean 159 | Clean 160 | ProjectExplorer.BuildSteps.Clean 161 | 162 | 2 163 | false 164 | 165 | Release 166 | Qt4ProjectManager.Qt4BuildConfiguration 167 | 0 168 | 169 | 170 | C:/Users/www/Desktop/build-01_sort-Desktop_Qt_5_14_2_MSVC2017_64bit-Profile 171 | 172 | 173 | true 174 | QtProjectManager.QMakeBuildStep 175 | true 176 | 177 | false 178 | true 179 | true 180 | 181 | 182 | true 183 | Qt4ProjectManager.MakeStep 184 | 185 | false 186 | 187 | 188 | false 189 | 190 | 2 191 | Build 192 | Build 193 | ProjectExplorer.BuildSteps.Build 194 | 195 | 196 | 197 | true 198 | Qt4ProjectManager.MakeStep 199 | 200 | true 201 | clean 202 | 203 | false 204 | 205 | 1 206 | Clean 207 | Clean 208 | ProjectExplorer.BuildSteps.Clean 209 | 210 | 2 211 | false 212 | 213 | Profile 214 | Qt4ProjectManager.Qt4BuildConfiguration 215 | 0 216 | 217 | 3 218 | 219 | 220 | 0 221 | Deploy 222 | Deploy 223 | ProjectExplorer.BuildSteps.Deploy 224 | 225 | 1 226 | ProjectExplorer.DefaultDeployConfiguration 227 | 228 | 1 229 | 230 | 231 | dwarf 232 | 233 | cpu-cycles 234 | 235 | 236 | 250 237 | 238 | -e 239 | cpu-cycles 240 | --call-graph 241 | dwarf,4096 242 | -F 243 | 250 244 | 245 | -F 246 | true 247 | 4096 248 | false 249 | false 250 | 1000 251 | 252 | true 253 | 254 | false 255 | false 256 | false 257 | false 258 | true 259 | 0.01 260 | 10 261 | true 262 | kcachegrind 263 | 1 264 | 25 265 | 266 | 1 267 | true 268 | false 269 | true 270 | valgrind 271 | 272 | 0 273 | 1 274 | 2 275 | 3 276 | 4 277 | 5 278 | 6 279 | 7 280 | 8 281 | 9 282 | 10 283 | 11 284 | 12 285 | 13 286 | 14 287 | 288 | 2 289 | 290 | Qt4ProjectManager.Qt4RunConfiguration:C:/Users/www/Desktop/01_sort/01_sort.pro 291 | C:/Users/www/Desktop/01_sort/01_sort.pro 292 | 293 | false 294 | 295 | false 296 | true 297 | true 298 | false 299 | false 300 | true 301 | 302 | C:/Users/www/Desktop/build-01_sort-Desktop_Qt_5_14_2_MSVC2017_64bit-Release 303 | 304 | 1 305 | 306 | 307 | 308 | ProjectExplorer.Project.TargetCount 309 | 1 310 | 311 | 312 | ProjectExplorer.Project.Updater.FileVersion 313 | 22 314 | 315 | 316 | Version 317 | 22 318 | 319 | 320 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/01_sort/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | #include 4 | 5 | //程序的开始入口 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication a(argc, argv); 9 | MainWindow w; 10 | w.show(); 11 | return a.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/01_sort/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | #include 4 | 5 | MainWindow::MainWindow(QWidget *parent) 6 | : QMainWindow(parent) 7 | , ui(new Ui::MainWindow) 8 | { 9 | //主页面的构造函数,用于设置一些基础布局、显示内容等 10 | ui->setupUi(this); 11 | 12 | this->setWindowTitle("1852979_01_sort"); 13 | this->setWindowFlags(Qt::WindowCloseButtonHint|Qt::WindowMinimizeButtonHint); 14 | this->setFixedSize(this->width(), this->height()); 15 | } 16 | 17 | MainWindow::~MainWindow() 18 | { 19 | delete ui; 20 | } 21 | 22 | 23 | void MainWindow::on_pushButton_released() 24 | { 25 | //该按钮用于向子页面传入用户输入的信息 26 | 27 | //这里获取用户选择的排序方式 28 | sort_style=ui->choose_in->currentIndex(); 29 | 30 | //这里先以QString的方式读入用户输入的全部文本,再转换为便于处理的char*数组 31 | QString qs=ui->num_in->toPlainText(); 32 | char *qc = NULL; 33 | QByteArray ba = qs.toLatin1(); 34 | qc = (char *)malloc(ba.length() + 1); 35 | memset(qc, 0, ba.length()); 36 | memcpy(qc, ba.data(), ba.length()); 37 | qc[ba.length()] = '\0'; 38 | 39 | //这里用于注意读取用户输入的字符串 40 | long long temp = 0; 41 | bool flag=false; 42 | for(int i=0;i='0'&&qc[i]<='9'){ 46 | temp=temp*10+(long long)(qc[i]-'0'); 47 | }else if(qc[i]==' '){ 48 | if(flag){ 49 | temp=-temp; 50 | } 51 | the_num[the_len]=temp; 52 | the_len++; 53 | flag=false; 54 | temp=0; 55 | }else{ 56 | //如果用户输入的信息非法,则不再读入,直接调用error窗口 57 | 58 | dsp=new re_dialog(); 59 | dsp->show(); 60 | 61 | ui->num_in->setMarkdown(""); 62 | 63 | the_len=0; 64 | return; 65 | } 66 | 67 | if(i==ba.length()-1 && qc[i]!=' '){ 68 | if(flag){ 69 | temp=-temp; 70 | } 71 | the_num[the_len]=temp; 72 | the_len++; 73 | } 74 | } 75 | 76 | qDebug()<show(); 82 | 83 | //主窗口初始化 84 | the_len=0; 85 | ui->num_in->setMarkdown(""); 86 | ui->choose_in->setCurrentIndex(0); 87 | } 88 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/01_sort/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | //这里是主窗口的头文件,用于导入其他窗口的头文件,同时也是main函数所指引的程序开始的起点 5 | 6 | #include 7 | #include "subwindow.h" 8 | #include "re_dialog.h" 9 | 10 | QT_BEGIN_NAMESPACE 11 | namespace Ui { class MainWindow; } 12 | QT_END_NAMESPACE 13 | 14 | class MainWindow : public QMainWindow 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | MainWindow(QWidget *parent = nullptr); 20 | ~MainWindow(); 21 | long long the_num[1000]; //the_num用于存储用户输入的所有数据 22 | int the_len=0; //the_len表示用户输入数据的个数 23 | int sort_style=0; //sort_style表示用户选择的排序方式 24 | 25 | subwindow *wsp; //定义了两个子页面指针,用于随时打开 26 | re_dialog *dsp; 27 | 28 | private slots: 29 | void on_pushButton_released(); // 按钮槽函数 30 | 31 | private: 32 | Ui::MainWindow *ui; 33 | }; 34 | #endif // MAINWINDOW_H 35 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/01_sort/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 653 10 | 403 11 | 12 | 13 | 14 | 15 | 16777215 16 | 16777215 17 | 18 | 19 | 20 | MainWindow 21 | 22 | 23 | 24 | 25 | 26 | 20 27 | 10 28 | 571 29 | 61 30 | 31 | 32 | 33 | border-width:0; 34 | 35 | 36 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 37 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 38 | p, li { white-space: pre-wrap; } 39 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> 40 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">请输入您想要进行排序的数字序列:(数字间请使用空格分隔,数字范围为<span style=" font-family:'Arial','sans-serif'; font-size:14px; color:#333333; background-color:#ffffff;">-2^63到2^63-1</span>)</p></body></html> 41 | 42 | 43 | 44 | 45 | 46 | 60 47 | 100 48 | 451 49 | 111 50 | 51 | 52 | 53 | 54 | 55 | 56 | 20 57 | 240 58 | 321 59 | 41 60 | 61 | 62 | 63 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 64 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 65 | p, li { white-space: pre-wrap; } 66 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> 67 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">请选择您想要进行的排序方式:</p></body></html> 68 | 69 | 70 | 71 | 72 | 73 | 380 74 | 240 75 | 151 76 | 41 77 | 78 | 79 | 80 | false 81 | 82 | 83 | 84 | 直接插入排序 85 | 86 | 87 | 88 | 89 | 折半插入排序 90 | 91 | 92 | 93 | 94 | 希尔排序 95 | 96 | 97 | 98 | 99 | 冒泡排序 100 | 101 | 102 | 103 | 104 | 快速排序 105 | 106 | 107 | 108 | 109 | 简单选择排序 110 | 111 | 112 | 113 | 114 | 115 | 116 | 470 117 | 310 118 | 111 119 | 41 120 | 121 | 122 | 123 | 开始排序 124 | 125 | 126 | 127 | 128 | 129 | 130 | 0 131 | 0 132 | 653 133 | 21 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/01_sort/re_dialog.cpp: -------------------------------------------------------------------------------- 1 | #include "re_dialog.h" 2 | #include "ui_re_dialog.h" 3 | 4 | re_dialog::re_dialog(QWidget *parent) : 5 | QDialog(parent), 6 | ui(new Ui::re_dialog) 7 | { 8 | //错误窗口构造函数,显示布局 9 | ui->setupUi(this); 10 | 11 | this->setWindowTitle("wrong!"); 12 | this->setWindowFlags(Qt::WindowCloseButtonHint|Qt::WindowMinimizeButtonHint); 13 | this->setFixedSize(this->width(), this->height()); 14 | } 15 | 16 | re_dialog::~re_dialog() 17 | { 18 | delete ui; 19 | } 20 | 21 | void re_dialog::on_pushButton_released() 22 | { 23 | this->close(); 24 | } 25 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/01_sort/re_dialog.h: -------------------------------------------------------------------------------- 1 | #ifndef RE_DIALOG_H 2 | #define RE_DIALOG_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class re_dialog; 8 | } 9 | 10 | class re_dialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit re_dialog(QWidget *parent = nullptr); 16 | ~re_dialog(); 17 | 18 | private slots: 19 | void on_pushButton_released(); //关闭按钮槽函数 20 | 21 | private: 22 | Ui::re_dialog *ui; 23 | }; 24 | 25 | #endif // RE_DIALOG_H 26 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/01_sort/re_dialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | re_dialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 260 10 | 125 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 80 20 | 70 21 | 91 22 | 31 23 | 24 | 25 | 26 | 好的 27 | 28 | 29 | 30 | 31 | 32 | 10 33 | 20 34 | 241 35 | 41 36 | 37 | 38 | 39 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 40 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 41 | p, li { white-space: pre-wrap; } 42 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> 43 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">请您按照正确格式输入数列</p></body></html> 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/01_sort/subwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "subwindow.h" 2 | #include "ui_subwindow.h" 3 | #include 4 | 5 | subwindow::subwindow(QWidget *parent, int sort_style, int the_len, long long the_num[1000]) : 6 | QWidget(parent), 7 | ui(new Ui::subwindow) 8 | { 9 | //次级窗口构造函数,显示布局 10 | ui->setupUi(this); 11 | 12 | this->setWindowTitle("sort_result"); 13 | this->setWindowFlags(Qt::WindowCloseButtonHint|Qt::WindowMinimizeButtonHint); 14 | this->setFixedSize(this->width(), this->height()); 15 | 16 | //对传入的信息进行保留记录 17 | this->sort_style = sort_style; 18 | this->the_len = the_len; 19 | for (int i = 0; i < the_len; i++) { 20 | this->the_num[i] = the_num[i]; 21 | } 22 | 23 | //在文本框中提示当前选择的排序方式 24 | char title_qs[20]; 25 | switch (sort_style) { 26 | case 0: 27 | qstrcpy(title_qs, "直接插入排序"); 28 | one(); 29 | break; 30 | case 1: 31 | qstrcpy(title_qs, "折半插入排序"); 32 | two(); 33 | break; 34 | case 2: 35 | qstrcpy(title_qs, "希尔排序"); 36 | three(); 37 | break; 38 | case 3: 39 | qstrcpy(title_qs, "冒泡排序"); 40 | four(); 41 | break; 42 | case 4: 43 | qstrcpy(title_qs, "快速排序"); 44 | five(); 45 | break; 46 | case 5: 47 | qstrcpy(title_qs, "简单选择排序"); 48 | six(); 49 | break; 50 | } 51 | 52 | //进行提示,注意中文编码要进行码值转换 53 | ui->out_title->setMarkdown(QString::fromLocal8Bit(title_qs) + ui->out_title->toPlainText()); 54 | 55 | //首先展示用户输入的待排序数组 56 | QString qs; 57 | qs += QString::number(the_num[0]); 58 | for (int i = 1; i < the_len; i++) { 59 | qs = qs + ',' + QString::number(the_num[i]); 60 | } 61 | 62 | ui->out_text->setMarkdown(qs); 63 | } 64 | 65 | //该函数用于比较当前数组与前一阶段的状态差异,并返回标红处理后的字符串 66 | QString subwindow::get_qs(long long *old, long long *current) { 67 | QString ans; 68 | bool flag = true; 69 | 70 | if (old[0] != current[0]) { 71 | flag = false; 72 | //利用标签布局方式对对应文本进行标红处理 73 | ans = ans + "" + QString::number(current[0]) + ""; 74 | } 75 | else { 76 | ans = ans + QString::number(current[0]); 77 | } 78 | for (int i = 1; i < the_len; i++) { 79 | if (old[i] != current[i]) { 80 | flag = false; 81 | ans = ans + "," + "" + QString::number(current[i]) + ""; 82 | } 83 | else { 84 | ans = ans + "," + QString::number(current[i]); 85 | } 86 | } 87 | 88 | //如果没有数字发生变化,不进行记录,返回NOT 89 | if (flag) { 90 | return "NOT"; 91 | } 92 | 93 | return ans; 94 | } 95 | 96 | //用于让_old数组记录前一步状态 97 | void subwindow::to_old() { 98 | for (int i = 0; i < the_len; i++) { 99 | _old[i] = _cur[i]; 100 | } 101 | } 102 | 103 | //用于让_old和_cur都保持原始状态 104 | void subwindow::init_old() { 105 | for (int i = 0; i < the_len; i++) { 106 | _old[i] = _cur[i] = the_num[i]; 107 | } 108 | } 109 | 110 | //直接插入代码实现 111 | void subwindow::one() { 112 | QString qs; 113 | int i,j; 114 | long long temp; 115 | 116 | init_old(); 117 | 118 | for (i = 1; i < the_len; ++i){ 119 | temp = _cur[i]; 120 | 121 | for (j = i - 1; j >= 0; --j){ 122 | if (temp < _cur[j]){ 123 | _cur[j + 1] = _cur[j]; 124 | } 125 | else { break; } 126 | } 127 | 128 | _cur[j + 1] = temp; 129 | 130 | qs = get_qs(_old, _cur); 131 | if (qs != "NOT") { 132 | the_out.push_back(qs); 133 | qs.clear(); 134 | to_old(); 135 | } 136 | } 137 | } 138 | 139 | //折半插入排序代码实现 140 | void subwindow::two() { 141 | QString qs; 142 | int mid, low, high; 143 | long long temp; 144 | 145 | init_old(); 146 | 147 | for (int i = 1; i < the_len; i++) { 148 | low = 0; 149 | high = i - 1; 150 | temp = _cur[i]; 151 | 152 | while (low <= high) { 153 | mid = (low + high) / 2; 154 | if (_cur[i] < _cur[mid]) { 155 | high = mid - 1; 156 | } 157 | else { 158 | low = mid + 1; 159 | } 160 | } 161 | 162 | for (int j = i - 1; j >= high + 1; j--) { 163 | _cur[j + 1] = _cur[j]; 164 | } 165 | 166 | _cur[high + 1] = temp; 167 | 168 | qs = get_qs(_old, _cur); 169 | if (qs != "NOT") { 170 | the_out.push_back(qs); 171 | qs.clear(); 172 | to_old(); 173 | } 174 | } 175 | } 176 | 177 | //希尔排序代码实现 178 | void subwindow::three() { 179 | QString qs; 180 | const int the_gap = 2; //这里我默认选用gap为2 181 | int j; 182 | long long temp; 183 | int gap = the_len / the_gap + 1; 184 | 185 | init_old(); 186 | 187 | while (gap >= 1) { 188 | for (int i = gap; i < the_len; ++i) { 189 | temp = _cur[i]; 190 | j = i; 191 | 192 | while (j >= gap && temp < _cur[j - gap]) { 193 | _cur[j] = _cur[j - gap]; 194 | j -= gap; 195 | } 196 | 197 | _cur[j] = temp; 198 | 199 | qs = get_qs(_old, _cur); 200 | if (qs != "NOT") { 201 | the_out.push_back(qs); 202 | qs.clear(); 203 | to_old(); 204 | } 205 | } 206 | gap = gap / the_gap; 207 | } 208 | } 209 | 210 | //冒泡排序代码实现 211 | void subwindow::four() { 212 | QString qs; 213 | long long temp; 214 | 215 | init_old(); 216 | 217 | for (int i = the_len; i > 0; i--) { 218 | for (int j = 0; j < i - 1; j++) { 219 | if (_cur[j] > _cur[j + 1]) { 220 | temp = _cur[j]; 221 | _cur[j] = _cur[j + 1]; 222 | _cur[j + 1] = temp; 223 | 224 | qs = get_qs(_old, _cur); 225 | if (qs != "NOT") { 226 | the_out.push_back(qs); 227 | qs.clear(); 228 | to_old(); 229 | } 230 | } 231 | } 232 | } 233 | } 234 | 235 | //快速排序代码实现 236 | void subwindow::quick(int q, int p){ 237 | QString qs; 238 | 239 | int i = q; 240 | int j = p; 241 | long long temp = _cur[i]; 242 | 243 | if (i < j) 244 | { 245 | while (i < j) 246 | { 247 | while (i < j && _cur[j] >= temp) 248 | j--; 249 | if (i < j) 250 | { 251 | _cur[i] = _cur[j]; 252 | i++; 253 | } 254 | 255 | while (i < j && temp > _cur[i]) 256 | i++; 257 | if (i < j) 258 | { 259 | _cur[j] = _cur[i]; 260 | j--; 261 | } 262 | 263 | } 264 | 265 | _cur[i] = temp; 266 | 267 | qs = get_qs(_old, _cur); 268 | if (qs != "NOT") { 269 | the_out.push_back(qs); 270 | qs.clear(); 271 | to_old(); 272 | } 273 | 274 | quick(q, i - 1); 275 | quick(i + 1, p); 276 | } 277 | } 278 | 279 | void subwindow::five() { 280 | init_old(); 281 | 282 | quick(0,the_len-1); 283 | } 284 | 285 | //简单选择排序代码实现 286 | void subwindow::six() { 287 | QString qs; 288 | int temp = 0; 289 | long long bios; 290 | 291 | init_old(); 292 | 293 | for (int i = 0; i < the_len; i++) { 294 | temp = i; 295 | for (int j = i + 1; j < the_len; j++) { 296 | if (_cur[temp] > _cur[j]) { 297 | temp = j; 298 | } 299 | } 300 | if (temp != i) { 301 | bios = _cur[temp]; 302 | _cur[temp] = _cur[i]; 303 | _cur[i] = bios; 304 | } 305 | 306 | qs = get_qs(_old, _cur); 307 | if (qs != "NOT") { 308 | the_out.push_back(qs); 309 | qs.clear(); 310 | to_old(); 311 | } 312 | } 313 | } 314 | 315 | subwindow::~subwindow() 316 | { 317 | delete ui; 318 | } 319 | 320 | //下一步按钮操作 321 | void subwindow::on_pushButton_released() 322 | { 323 | //到最后一步无法执行“下一步”操作 324 | if (vec_index == the_out.length()) { 325 | return; 326 | } 327 | ui->out_text->setMarkdown(the_out[vec_index]); 328 | vec_index++; 329 | } 330 | 331 | //多步至最后按钮操作 332 | void subwindow::on_pushButton_2_released() 333 | { 334 | //vec_index直接到最后一步 335 | vec_index = the_out.length() - 1; 336 | ui->out_text->setMarkdown(the_out[vec_index]); 337 | vec_index++; 338 | } 339 | 340 | //上一步按钮操作 341 | void subwindow::on_pushButton_3_released() 342 | { 343 | //在最开始无法进行上一部操作 344 | if (vec_index == 0) { 345 | return; 346 | } 347 | if (vec_index == 1) { 348 | vec_index = 0; 349 | QString qs; 350 | qs += QString::number(the_num[0]); 351 | for (int i = 1; i < the_len; i++) { 352 | qs = qs + ',' + QString::number(the_num[i]); 353 | } 354 | ui->out_text->setMarkdown(qs); 355 | return; 356 | } 357 | vec_index -= 2; 358 | ui->out_text->setMarkdown(the_out[vec_index]); 359 | vec_index++; 360 | } 361 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/01_sort/subwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef SUBWINDOW_H 2 | #define SUBWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | namespace Ui { 8 | class subwindow; 9 | } 10 | 11 | class subwindow : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | //这里的子页面构造函数因为要从主页面拿数据,所以采用传入构造参数的方式向子页面传递数据 17 | explicit subwindow(QWidget *parent = nullptr,int sort_style=0,int the_len=0,long long *the_num=nullptr); 18 | ~subwindow(); 19 | 20 | //下列三个变量的含义与主页面中的相同 21 | int sort_style,the_len; 22 | long long the_num[1000]; 23 | 24 | QVector the_out; //这个vector用于存储每一步数组的变化情况 25 | int vec_index=0; //vec_index用于记录用户当前查看的是第几步,便于记录 26 | 27 | private slots: 28 | //分别对应三个按钮的槽函数 29 | void on_pushButton_released(); 30 | 31 | void on_pushButton_2_released(); 32 | 33 | void on_pushButton_3_released(); 34 | 35 | private: 36 | Ui::subwindow *ui; 37 | 38 | long long _old[1000],_cur[1000]; 39 | 40 | QString get_qs(long long old[1000],long long current[1000]); 41 | void to_old(); 42 | void init_old(); 43 | 44 | //直接插入排序 45 | void one(); 46 | 47 | //折半插入排序 48 | void two(); 49 | 50 | //希尔排序 51 | void three(); 52 | 53 | //冒泡排序 54 | void four(); 55 | 56 | //快速排序 57 | void quick(int q, int p); 58 | void five(); 59 | 60 | //简单选择排序 61 | void six(); 62 | }; 63 | 64 | #endif // SUBWINDOW_H 65 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/01_sort/subwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | subwindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 666 10 | 395 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 40 20 | 30 21 | 571 22 | 51 23 | 24 | 25 | 26 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 27 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 28 | p, li { white-space: pre-wrap; } 29 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> 30 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">的排序结果如下:</p></body></html> 31 | 32 | 33 | 34 | 35 | 36 | 40 37 | 100 38 | 571 39 | 141 40 | 41 | 42 | 43 | 44 | 45 | 46 | 70 47 | 280 48 | 131 49 | 41 50 | 51 | 52 | 53 | 下一步 54 | 55 | 56 | 57 | 58 | 59 | 450 60 | 280 61 | 131 62 | 41 63 | 64 | 65 | 66 | 多步至结束 67 | 68 | 69 | 70 | 71 | 72 | 260 73 | 280 74 | 131 75 | 41 76 | 77 | 78 | 79 | 上一步 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/02_subway/02_subway.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | add_sta.cpp \ 20 | add_way.cpp \ 21 | error.cpp \ 22 | main.cpp \ 23 | mainwindow.cpp 24 | 25 | HEADERS += \ 26 | add_sta.h \ 27 | add_way.h \ 28 | error.h \ 29 | mainwindow.h \ 30 | station.h 31 | 32 | FORMS += \ 33 | add_sta.ui \ 34 | add_way.ui \ 35 | error.ui \ 36 | mainwindow.ui 37 | 38 | # Default rules for deployment. 39 | qnx: target.path = /tmp/$${TARGET}/bin 40 | else: unix:!android: target.path = /opt/$${TARGET}/bin 41 | !isEmpty(target.path): INSTALLS += target 42 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/02_subway/02_subway.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {7b6b20ad-47af-446b-aa4f-d8c02f64e52a} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 1 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | -fno-delayed-template-parsing 60 | 61 | true 62 | 63 | 64 | 65 | ProjectExplorer.Project.Target.0 66 | 67 | Desktop Qt 5.14.2 MSVC2017 64bit 68 | Desktop Qt 5.14.2 MSVC2017 64bit 69 | qt.qt5.5142.win64_msvc2017_64_kit 70 | 1 71 | 0 72 | 0 73 | 74 | C:/Users/www/Documents/build-02_subway-Desktop_Qt_5_14_2_MSVC2017_64bit-Debug 75 | 76 | 77 | true 78 | QtProjectManager.QMakeBuildStep 79 | true 80 | 81 | false 82 | false 83 | false 84 | 85 | 86 | true 87 | Qt4ProjectManager.MakeStep 88 | 89 | false 90 | 91 | 92 | false 93 | 94 | 2 95 | Build 96 | Build 97 | ProjectExplorer.BuildSteps.Build 98 | 99 | 100 | 101 | true 102 | Qt4ProjectManager.MakeStep 103 | 104 | true 105 | clean 106 | 107 | false 108 | 109 | 1 110 | Clean 111 | Clean 112 | ProjectExplorer.BuildSteps.Clean 113 | 114 | 2 115 | false 116 | 117 | Debug 118 | Qt4ProjectManager.Qt4BuildConfiguration 119 | 2 120 | 121 | 122 | C:/Users/www/Documents/build-02_subway-Desktop_Qt_5_14_2_MSVC2017_64bit-Release 123 | 124 | 125 | true 126 | QtProjectManager.QMakeBuildStep 127 | false 128 | 129 | false 130 | false 131 | true 132 | 133 | 134 | true 135 | Qt4ProjectManager.MakeStep 136 | 137 | false 138 | 139 | 140 | false 141 | 142 | 2 143 | Build 144 | Build 145 | ProjectExplorer.BuildSteps.Build 146 | 147 | 148 | 149 | true 150 | Qt4ProjectManager.MakeStep 151 | 152 | true 153 | clean 154 | 155 | false 156 | 157 | 1 158 | Clean 159 | Clean 160 | ProjectExplorer.BuildSteps.Clean 161 | 162 | 2 163 | false 164 | 165 | Release 166 | Qt4ProjectManager.Qt4BuildConfiguration 167 | 0 168 | 169 | 170 | C:/Users/www/Documents/build-02_subway-Desktop_Qt_5_14_2_MSVC2017_64bit-Profile 171 | 172 | 173 | true 174 | QtProjectManager.QMakeBuildStep 175 | true 176 | 177 | false 178 | true 179 | true 180 | 181 | 182 | true 183 | Qt4ProjectManager.MakeStep 184 | 185 | false 186 | 187 | 188 | false 189 | 190 | 2 191 | Build 192 | Build 193 | ProjectExplorer.BuildSteps.Build 194 | 195 | 196 | 197 | true 198 | Qt4ProjectManager.MakeStep 199 | 200 | true 201 | clean 202 | 203 | false 204 | 205 | 1 206 | Clean 207 | Clean 208 | ProjectExplorer.BuildSteps.Clean 209 | 210 | 2 211 | false 212 | 213 | Profile 214 | Qt4ProjectManager.Qt4BuildConfiguration 215 | 0 216 | 217 | 3 218 | 219 | 220 | 0 221 | Deploy 222 | Deploy 223 | ProjectExplorer.BuildSteps.Deploy 224 | 225 | 1 226 | ProjectExplorer.DefaultDeployConfiguration 227 | 228 | 1 229 | 230 | 231 | dwarf 232 | 233 | cpu-cycles 234 | 235 | 236 | 250 237 | 238 | -e 239 | cpu-cycles 240 | --call-graph 241 | dwarf,4096 242 | -F 243 | 250 244 | 245 | -F 246 | true 247 | 4096 248 | false 249 | false 250 | 1000 251 | 252 | true 253 | 254 | false 255 | false 256 | false 257 | false 258 | true 259 | 0.01 260 | 10 261 | true 262 | kcachegrind 263 | 1 264 | 25 265 | 266 | 1 267 | true 268 | false 269 | true 270 | valgrind 271 | 272 | 0 273 | 1 274 | 2 275 | 3 276 | 4 277 | 5 278 | 6 279 | 7 280 | 8 281 | 9 282 | 10 283 | 11 284 | 12 285 | 13 286 | 14 287 | 288 | 2 289 | 290 | Qt4ProjectManager.Qt4RunConfiguration:C:/Users/www/Documents/02_subway/02_subway.pro 291 | C:/Users/www/Documents/02_subway/02_subway.pro 292 | 293 | false 294 | 295 | false 296 | true 297 | true 298 | false 299 | false 300 | true 301 | 302 | C:/Users/www/Documents/build-02_subway-Desktop_Qt_5_14_2_MSVC2017_64bit-Release 303 | 304 | 1 305 | 306 | 307 | 308 | ProjectExplorer.Project.TargetCount 309 | 1 310 | 311 | 312 | ProjectExplorer.Project.Updater.FileVersion 313 | 22 314 | 315 | 316 | Version 317 | 22 318 | 319 | 320 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/02_subway/add_sta.cpp: -------------------------------------------------------------------------------- 1 | #include "add_sta.h" 2 | #include "ui_add_sta.h" 3 | 4 | //该文件主要用于站点的添加 5 | 6 | add_sta::add_sta(QWidget *parent, QVector *stas, int *idp) : 7 | QDialog(parent), 8 | ui(new Ui::add_sta) 9 | { 10 | //添加站点的构造函数,显示布局并设置一些显示的内容 11 | ui->setupUi(this); 12 | 13 | this->setWindowTitle("Add new station"); 14 | this->setWindowFlags(Qt::WindowCloseButtonHint|Qt::WindowMinimizeButtonHint); 15 | this->setFixedSize(this->width(), this->height()); 16 | 17 | sts=stas; 18 | id_num=idp; 19 | } 20 | 21 | add_sta::~add_sta() 22 | { 23 | delete ui; 24 | } 25 | 26 | //添加按钮的槽函数 27 | void add_sta::on_pushButton_released() 28 | { 29 | //用于以QString的方式获取用户输入的内容 30 | QString qs=ui->t_name->toPlainText(); 31 | std::string qstr; 32 | 33 | //将用户获取的站点转化为索引值 34 | int a,b; 35 | qstr=std::string(qs.toLocal8Bit()); 36 | station nst(qstr); 37 | 38 | a=(ui->t_x->toPlainText()).toInt(); 39 | b=(ui->t_y->toPlainText()).toInt(); 40 | 41 | //确定站点绘制位置 42 | nst.addr=QPoint(0.75*a,0.75*b); 43 | 44 | nst.id=*id_num; 45 | (*id_num)++; 46 | 47 | (*sts).push_back(nst); 48 | 49 | this->close(); 50 | } 51 | 52 | void add_sta::on_pushButton_2_released() 53 | { 54 | this->close(); 55 | } 56 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/02_subway/add_sta.h: -------------------------------------------------------------------------------- 1 | #ifndef ADD_STA_H 2 | #define ADD_STA_H 3 | 4 | #include 5 | #include "station.h" 6 | #include "string" 7 | 8 | //该头文件用于站点的添加 9 | 10 | namespace Ui { 11 | class add_sta; 12 | } 13 | 14 | class add_sta : public QDialog 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | explicit add_sta(QWidget *parent = nullptr,QVector *stas=nullptr,int *idp=nullptr); 20 | ~add_sta(); 21 | QVector* sts; 22 | int* id_num; 23 | 24 | private slots: 25 | void on_pushButton_released(); 26 | 27 | void on_pushButton_2_released(); 28 | 29 | private: 30 | Ui::add_sta *ui; 31 | }; 32 | 33 | #endif // ADD_STA_H 34 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/02_subway/add_sta.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | add_sta 4 | 5 | 6 | 7 | 0 8 | 0 9 | 509 10 | 320 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 20 20 | 40 21 | 271 22 | 41 23 | 24 | 25 | 26 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 27 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 28 | p, li { white-space: pre-wrap; } 29 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> 30 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">请输入站点名称:</p></body></html> 31 | 32 | 33 | 34 | 35 | 36 | 20 37 | 90 38 | 271 39 | 41 40 | 41 | 42 | 43 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 44 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 45 | p, li { white-space: pre-wrap; } 46 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> 47 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">请输入站点X坐标(30~1970):</p></body></html> 48 | 49 | 50 | 51 | 52 | 53 | 20 54 | 140 55 | 271 56 | 41 57 | 58 | 59 | 60 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 61 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 62 | p, li { white-space: pre-wrap; } 63 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> 64 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">请输入站点Y坐标(30~1970):</p></body></html> 65 | 66 | 67 | 68 | 69 | 70 | 310 71 | 40 72 | 151 73 | 41 74 | 75 | 76 | 77 | 78 | 79 | 80 | 310 81 | 90 82 | 151 83 | 41 84 | 85 | 86 | 87 | 88 | 89 | 90 | 310 91 | 140 92 | 151 93 | 41 94 | 95 | 96 | 97 | 98 | 99 | 100 | 240 101 | 240 102 | 91 103 | 41 104 | 105 | 106 | 107 | 确定 108 | 109 | 110 | 111 | 112 | 113 | 370 114 | 240 115 | 91 116 | 41 117 | 118 | 119 | 120 | 取消 121 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/02_subway/add_way.cpp: -------------------------------------------------------------------------------- 1 | #include "add_way.h" 2 | #include "ui_add_way.h" 3 | 4 | //该函数用于添加轨道线路 5 | 6 | add_way::add_way(QWidget *parent,QVector* sts,QVector* sbs) : 7 | QDialog(parent), 8 | ui(new Ui::add_way) 9 | { 10 | //建立轨道线的头函数,设置布局与一些其他显示内容 11 | ui->setupUi(this); 12 | 13 | this->setWindowTitle("Add new subway line"); 14 | this->setWindowFlags(Qt::WindowCloseButtonHint|Qt::WindowMinimizeButtonHint); 15 | this->setFixedSize(this->width(), this->height()); 16 | 17 | this->sbs=sbs; 18 | this->sts=sts; 19 | } 20 | 21 | add_way::~add_way() 22 | { 23 | delete ui; 24 | } 25 | 26 | //确认按钮的槽函数 27 | void add_way::on_pushButton_released() 28 | { 29 | //新建一个 subway_类变量,开始新建地铁线 30 | subway_ nsy; 31 | //获取用户输入的站点索引值、地铁的编号 32 | int a=get_id(ui->t_start->toPlainText()); 33 | int b=get_id(ui->t_end->toPlainText()); 34 | int num=ui->t_num->toPlainText().toInt(); 35 | 36 | //若用户输入错误,则弹出error窗口 37 | if(a==-1||b==-1){ 38 | error* esp=new error; 39 | esp->show(); 40 | if(a==-1){ 41 | ui->t_start->setMarkdown(""); 42 | } 43 | if(b==-1){ 44 | ui->t_end->setMarkdown(""); 45 | } 46 | return; 47 | } 48 | 49 | //开始构建地铁信息 50 | nsy.id=num; 51 | nsy.sts.push_back(a); 52 | nsy.sts.push_back(b); 53 | 54 | (*sts)[a].links.push_back(b); 55 | (*sts)[a].lines.push_back(num); 56 | (*sts)[b].links.push_back(a); 57 | (*sts)[b].lines.push_back(num); 58 | 59 | //压入地铁容器,新建地铁成功 60 | sbs->push_back(nsy); 61 | update(); 62 | 63 | this->close(); 64 | } 65 | 66 | void add_way::on_pushButton_2_released() 67 | { 68 | this->close(); 69 | } 70 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/02_subway/add_way.h: -------------------------------------------------------------------------------- 1 | #ifndef ADD_WAY_H 2 | #define ADD_WAY_H 3 | 4 | #include 5 | #include "station.h" 6 | #include "error.h" 7 | 8 | namespace Ui { 9 | class add_way; 10 | } 11 | 12 | class add_way : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | explicit add_way(QWidget *parent = nullptr,QVector* sts = nullptr,QVector* sbs = nullptr); 18 | ~add_way(); 19 | QVector* sts; 20 | QVector* sbs; 21 | 22 | int get_id(QString sp) { 23 | size_t temp = sts->size(); 24 | for (size_t i = 0; i < temp; i++) { 25 | if (sp == QString::fromLocal8Bit(((*sts)[i].name).data())) { 26 | return i; 27 | } 28 | } 29 | return -1; 30 | } 31 | 32 | private slots: 33 | void on_pushButton_released(); 34 | 35 | void on_pushButton_2_released(); 36 | 37 | private: 38 | Ui::add_way *ui; 39 | }; 40 | 41 | #endif // ADD_WAY_H 42 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/02_subway/add_way.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | add_way 4 | 5 | 6 | 7 | 0 8 | 0 9 | 486 10 | 320 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 310 20 | 90 21 | 151 22 | 41 23 | 24 | 25 | 26 | 27 | 28 | 29 | 20 30 | 40 31 | 271 32 | 41 33 | 34 | 35 | 36 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 37 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 38 | p, li { white-space: pre-wrap; } 39 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> 40 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">请输入轨道序号:</p></body></html> 41 | 42 | 43 | 44 | 45 | 46 | 20 47 | 90 48 | 271 49 | 41 50 | 51 | 52 | 53 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 54 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 55 | p, li { white-space: pre-wrap; } 56 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> 57 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">请输入要连接的段落起点:</p></body></html> 58 | 59 | 60 | 61 | 62 | 63 | 310 64 | 40 65 | 151 66 | 41 67 | 68 | 69 | 70 | 71 | 72 | 73 | 310 74 | 140 75 | 151 76 | 41 77 | 78 | 79 | 80 | 81 | 82 | 83 | 20 84 | 140 85 | 271 86 | 41 87 | 88 | 89 | 90 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 91 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 92 | p, li { white-space: pre-wrap; } 93 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> 94 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">请输入要连接的段落终点:</p></body></html> 95 | 96 | 97 | 98 | 99 | 100 | 200 101 | 230 102 | 101 103 | 41 104 | 105 | 106 | 107 | 确认 108 | 109 | 110 | 111 | 112 | 113 | 340 114 | 230 115 | 101 116 | 41 117 | 118 | 119 | 120 | 取消 121 | 122 | 123 | 124 | 125 | 126 | 127 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/02_subway/error.cpp: -------------------------------------------------------------------------------- 1 | #include "error.h" 2 | #include "ui_error.h" 3 | 4 | //该文件用于构建报错页面,只需要显示对应布局即可 5 | 6 | error::error(QWidget *parent) : 7 | QDialog(parent), 8 | ui(new Ui::error) 9 | { 10 | //构造函数,用于显示布局与其他内容的展示 11 | ui->setupUi(this); 12 | 13 | this->setWindowTitle("station wrong!"); 14 | this->setWindowFlags(Qt::WindowCloseButtonHint|Qt::WindowMinimizeButtonHint); 15 | this->setFixedSize(this->width(), this->height()); 16 | } 17 | 18 | error::~error() 19 | { 20 | delete ui; 21 | } 22 | 23 | void error::on_pushButton_released() 24 | { 25 | this->close(); 26 | } 27 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/02_subway/error.h: -------------------------------------------------------------------------------- 1 | #ifndef ERROR_H 2 | #define ERROR_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class error; 8 | } 9 | 10 | class error : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit error(QWidget *parent = nullptr); 16 | ~error(); 17 | 18 | private slots: 19 | void on_pushButton_released(); 20 | 21 | private: 22 | Ui::error *ui; 23 | }; 24 | 25 | #endif // ERROR_H 26 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/02_subway/error.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | error 4 | 5 | 6 | 7 | 0 8 | 0 9 | 362 10 | 164 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 10 20 | 20 21 | 341 22 | 51 23 | 24 | 25 | 26 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 27 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 28 | p, li { white-space: pre-wrap; } 29 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> 30 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">站点不存在,请确认您输入的站点名称</p></body></html> 31 | 32 | 33 | 34 | 35 | 36 | 140 37 | 99 38 | 91 39 | 31 40 | 41 | 42 | 43 | 好的 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/02_subway/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | #include 4 | 5 | //函数的入口 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication a(argc, argv); 9 | MainWindow w; 10 | w.show(); 11 | return a.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/02_subway/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | 4 | #include 5 | 6 | //该文件是本工程的核心文件,用于构建初始地铁线路图等 7 | 8 | MainWindow::MainWindow(QWidget *parent) 9 | : QMainWindow(parent) 10 | , ui(new Ui::MainWindow) 11 | { 12 | //构造函数,首先显示布局 13 | ui->setupUi(this); 14 | 15 | this->setWindowTitle("1852979_02_Shanghaisubway"); 16 | this->setWindowFlags(Qt::WindowCloseButtonHint|Qt::WindowMinimizeButtonHint); 17 | this->setFixedSize(this->width(), this->height()); 18 | 19 | //首先定义出17条地铁线 20 | for(int i=0;i<17;i++){ 21 | subway_ haha; 22 | sbs.push_back(haha); 23 | } 24 | 25 | //定义文本流文件,开始从subway_data.txt中读取地铁信息 26 | std::fstream fp; 27 | //打开文件 28 | fp.open("subway_data.txt"); 29 | if (!fp.is_open()) { 30 | exit(-1); 31 | } 32 | 33 | std::string temp; 34 | int a, b, subway; 35 | station* sp; 36 | int lp; 37 | int ssp; 38 | 39 | //依次构建17条地铁线 40 | for (int uhi = 0; uhi < 17; uhi++) { 41 | 42 | //首先读入地铁列号 43 | fp >> subway; 44 | //保证首站没有上一站 45 | lp = -1; 46 | sbs[uhi].id=subway; 47 | 48 | for (;;) { 49 | //读入站点名 50 | fp >> temp; 51 | //当读到终止符时完成当前地铁线的读入 52 | if (temp == "#") { 53 | break; 54 | } 55 | //读入站点坐标 56 | fp >> a >> b; 57 | 58 | //判断当前站点是否已经在已知站点库中 59 | if ((ssp = is_in(temp)) == -1) { 60 | //如果不在则新建一个站点 61 | sp = new station(temp); 62 | sp->id = id_num++; 63 | sp->addr=QPoint(a*0.75,b*0.75); 64 | 65 | //如果当前站点的经过路线中没有当前讨论的地铁线,则压入 66 | if (!way_is_in(*sp, subway)) { 67 | sp->lines.push_back(subway); 68 | } 69 | 70 | //如果存在上一站,则将上一站与这一站连接起来 71 | if (lp != -1) { 72 | if (!sta_is_in(stations[lp], sp->id)) { 73 | stations[lp].links.push_back(sp->id); 74 | } 75 | if (!sta_is_in(*sp, lp)) { 76 | sp->links.push_back(lp); 77 | } 78 | } 79 | 80 | //当前站记录位上一站 81 | lp = sp->id; 82 | 83 | //压入所有地铁站的容器 84 | stations.push_back(*sp); 85 | 86 | //释放空间 87 | delete sp; 88 | } 89 | else { 90 | //如果已有该站,则对已存在的站点进行操作 91 | 92 | //判断该站点是否已记录经过改路线地铁,没有则压入栈 93 | if (!way_is_in(stations[ssp], subway)) { 94 | stations[ssp].lines.push_back(subway); 95 | } 96 | 97 | //如果存在上一站,则将上一站与这一站连接起来 98 | if (lp != -1) { 99 | if (!sta_is_in(stations[lp], ssp)) { 100 | stations[lp].links.push_back(ssp); 101 | } 102 | if (!sta_is_in(stations[ssp], lp)) { 103 | stations[ssp].links.push_back(lp); 104 | } 105 | } 106 | //当前站记录为上一站 107 | lp = ssp; 108 | } 109 | sbs[uhi].sts.push_back(lp); 110 | } 111 | } 112 | } 113 | 114 | MainWindow::~MainWindow() 115 | { 116 | delete ui; 117 | } 118 | 119 | //该函数用于输出换乘路线 120 | void MainWindow::out_path(path pth) { 121 | int temp = pth.times; 122 | QString qs; 123 | 124 | for (int i = 0; i < temp; i++) { 125 | //换行 126 | if (i != 0) { 127 | qs+="

"; 128 | qs+="->"; 129 | qs+="

"; 130 | } 131 | //输出该站点的名称 132 | qs+="

"+QString::fromLocal8Bit((stations[pth.ids[i]].name).data()); 133 | qs+="..........."; 134 | 135 | //输出该站点被经过的所有地铁线 136 | for(int j=0;jt_out->setMarkdown(qs); 144 | } 145 | 146 | //定义Qt绘画时间,随生命周期调用,用于绘制外框、地铁线路图、最优换乘路径 147 | void MainWindow::paintEvent(QPaintEvent *) 148 | { 149 | //定义画笔QPainter 150 | QPainter painter(this); 151 | painter.setPen(QPen(Qt::black,4)); 152 | painter.drawRect(20,20,1460,1460); 153 | 154 | //首先绘制所有的地铁路线,根据列车编号绘制颜色 155 | for(int i=0;it_start->toPlainText(); 242 | QString qs2=ui->t_end->toPlainText(); 243 | 244 | if(get_id(qs)==-1||get_id(qs2)==-1){ 245 | error* sp=new error; 246 | sp->show(); 247 | if(get_id(qs)==-1){ 248 | ui->t_start->setMarkdown(""); 249 | } 250 | if(get_id(qs2)==-1){ 251 | ui->t_end->setMarkdown(""); 252 | } 253 | return; 254 | } 255 | 256 | //调用优化后的宽度优先搜索算法进行查找 257 | path ans=search(get_id(qs),get_id(qs2)); 258 | 259 | draw_it=ans; 260 | out_path(ans); 261 | 262 | 263 | //更新绘制 264 | update(); 265 | } 266 | 267 | void MainWindow::on_pushButton_2_released() 268 | { 269 | add_sta *sp= new add_sta(nullptr,&stations,&id_num); 270 | sp->show(); 271 | } 272 | 273 | void MainWindow::on_pushButton_3_released() 274 | { 275 | add_way *wp=new add_way(nullptr,&stations,&sbs); 276 | wp->show(); 277 | } 278 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/02_subway/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "station.h" 12 | #include "add_sta.h" 13 | #include "add_way.h" 14 | 15 | QT_BEGIN_NAMESPACE 16 | namespace Ui { class MainWindow; } 17 | QT_END_NAMESPACE 18 | 19 | class MainWindow : public QMainWindow 20 | { 21 | Q_OBJECT 22 | 23 | public: 24 | QVector stations; 25 | QVector sbs; 26 | 27 | path draw_it; 28 | 29 | int id_num = 0; 30 | 31 | MainWindow(QWidget *parent = nullptr); 32 | ~MainWindow(); 33 | 34 | int is_in(std::string sp) { 35 | size_t uhi = stations.size(); 36 | for (size_t i = 0; i < uhi; i++) { 37 | if (sp == stations[i].name) { 38 | return i; 39 | } 40 | } 41 | return -1; 42 | } 43 | 44 | bool way_is_in(station sp, int subway) { 45 | for (size_t i = 0; i < sp.lines.size(); i++) { 46 | if (subway == sp.lines[i]) { 47 | return true; 48 | } 49 | } 50 | return false; 51 | } 52 | 53 | bool sta_is_in(station sp, int sta_id) { 54 | for (size_t i = 0; i < sp.links.size(); i++) { 55 | if (sta_id == sp.links[i]) { 56 | return true; 57 | } 58 | } 59 | return false; 60 | } 61 | 62 | int get_id(QString sp) { 63 | size_t temp = stations.size(); 64 | for (size_t i = 0; i < temp; i++) { 65 | if (sp == QString::fromLocal8Bit((stations[i].name).data())) { 66 | return i; 67 | } 68 | } 69 | return -1; 70 | } 71 | 72 | bool is_in_path(int id, path pth) { 73 | for (int i = 0; i < pth.times; i++) { 74 | if (id == pth.ids[i]) { 75 | return true; 76 | } 77 | } 78 | return false; 79 | } 80 | 81 | 82 | void out_path(path pth); 83 | 84 | path search(int start, int end) { 85 | QVector vec; 86 | path orig; 87 | orig.ids.push_back(start); 88 | orig.names.push_back(stations[start].name); 89 | orig.times = 1; 90 | vec.push_back(orig); 91 | 92 | path temp, tw; 93 | int num, bios, uhi; 94 | 95 | for (;;) { 96 | temp = vec[0]; 97 | 98 | num = temp.ids[temp.ids.size() - 1]; 99 | bios = stations[num].links.size(); 100 | 101 | for (int i = 0; i < bios; i++) { 102 | uhi = stations[num].links[i]; 103 | tw = temp; 104 | if (uhi == end) { 105 | tw.ids.push_back(uhi); 106 | tw.names.push_back(stations[uhi].name); 107 | tw.times++; 108 | return tw; 109 | } 110 | if (!is_in_path(uhi, tw)) { 111 | tw.ids.push_back(uhi); 112 | tw.names.push_back(stations[uhi].name); 113 | tw.times++; 114 | for (;;) { 115 | if (uhi == end) { 116 | return tw; 117 | } 118 | if (stations[uhi].links.size() == 2) { 119 | if (stations[uhi].links[0] != tw.ids[tw.ids.size() - 2]) { 120 | uhi = stations[uhi].links[0]; 121 | tw.ids.push_back(uhi); 122 | tw.names.push_back(stations[uhi].name); 123 | tw.times++; 124 | } 125 | else if (stations[uhi].links[1] != tw.ids[tw.ids.size() - 2]) { 126 | uhi = stations[uhi].links[1]; 127 | tw.ids.push_back(uhi); 128 | tw.names.push_back(stations[uhi].name); 129 | tw.times++; 130 | } 131 | } 132 | else if (stations[uhi].links.size() == 1) { 133 | break; 134 | } 135 | else { 136 | vec.push_back(tw); 137 | break; 138 | } 139 | } 140 | } 141 | } 142 | 143 | vec.erase(vec.begin()); 144 | } 145 | } 146 | 147 | 148 | private: 149 | Ui::MainWindow *ui; 150 | 151 | protected: 152 | void paintEvent(QPaintEvent *); 153 | private slots: 154 | void on_pushButton_released(); 155 | void on_pushButton_2_released(); 156 | void on_pushButton_3_released(); 157 | }; 158 | 159 | #endif // MAINWINDOW_H 160 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/02_subway/mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 2000 10 | 1500 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 1535 21 | 60 22 | 150 23 | 40 24 | 25 | 26 | 27 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 28 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 29 | p, li { white-space: pre-wrap; } 30 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> 31 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">出发站点:</p></body></html> 32 | 33 | 34 | 35 | 36 | 37 | 1535 38 | 150 39 | 150 40 | 40 41 | 42 | 43 | 44 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 45 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 46 | p, li { white-space: pre-wrap; } 47 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> 48 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">目的站点:</p></body></html> 49 | 50 | 51 | 52 | 53 | 54 | 1750 55 | 60 56 | 150 57 | 40 58 | 59 | 60 | 61 | 62 | 63 | 64 | 1750 65 | 150 66 | 150 67 | 40 68 | 69 | 70 | 71 | 72 | 73 | 74 | 1630 75 | 230 76 | 171 77 | 41 78 | 79 | 80 | 81 | 开始规划路径 82 | 83 | 84 | 85 | 86 | 87 | 1535 88 | 300 89 | 365 90 | 881 91 | 92 | 93 | 94 | 95 | 96 | 97 | 1580 98 | 1230 99 | 281 100 | 71 101 | 102 | 103 | 104 | 添加站点 105 | 106 | 107 | 108 | 109 | 110 | 1580 111 | 1340 112 | 281 113 | 71 114 | 115 | 116 | 117 | 添加轨道线 118 | 119 | 120 | 121 | 122 | 123 | 124 | 0 125 | 0 126 | 2000 127 | 21 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_源代码/02_subway/station.h: -------------------------------------------------------------------------------- 1 | #ifndef STATION_H 2 | #define STATION_H 3 | 4 | #include 5 | #include 6 | 7 | class station { 8 | public: 9 | std::string name; 10 | QVector lines; 11 | QVector links; 12 | QPoint addr; 13 | int id = -1; 14 | station(std::string name) { 15 | this->name = name; 16 | } 17 | }; 18 | 19 | class path { 20 | public: 21 | QVector ids; 22 | QVector names; 23 | int times = 0; 24 | }; 25 | 26 | class subway_{ 27 | public: 28 | int id; 29 | QVector sts; 30 | }; 31 | 32 | #endif // STATION_H 33 | -------------------------------------------------------------------------------- /1850009_一二三_计算机科学与技术_设计说明书.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trigady/Array-sorting-display-and-Shanghai-Metro-Line-Planning/99fd27edf708443bf0e87304a951c1966f075276/1850009_一二三_计算机科学与技术_设计说明书.doc -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | 本人选择的是(09 排序+02地铁)的组合 2 | 3 | 2021.1.12 4 | 根据jgdl的建议,新增了release,已将可执行程序上传。 5 | -------------------------------------------------------------------------------- /《数据结构》课程设计计划及题目2020—给学生件.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trigady/Array-sorting-display-and-Shanghai-Metro-Line-Planning/99fd27edf708443bf0e87304a951c1966f075276/《数据结构》课程设计计划及题目2020—给学生件.doc --------------------------------------------------------------------------------