根据队列和栈的性质
队列找尾部最大的车厢号
栈找尾部最小的车厢号
栈、队列、数组可用STL或者自己实现
#pragma once
#include "vector.h"
#include "queue.h"
#include "stack.h"
#include <fstream>
const char* INPUTVECTORFILENAME = "carriagesRearrangement.txt";
const char* RESULTFILE = "carriagesResult.txt";
template<class T>
const int calculateK(Vector<T> & v) {
int k = 0;
for (int i = 1; i < v.size(); ++i) {
if (v[i] < v[i - 1]) {
k++;
}
}
return k;
}
void generateTestData(const char* fileName, const int &n) {
std::ofstream fout(fileName);
if (fout.is_open()) {
int *a = new int[n];
for (int i = 0; i < n; ++i) {
a[i] = i + 1;
}
for (int i = 0; i < n; ++i) {
std::swap(a[i], a[rand() % n]);
}
for (int i = 0; i < n; ++i) {
fout << a[i] << ' ';
}
fout.close();
}
}
template<class T>
void inputVectorFromFile(Vector<T> & v, const char* fileName) {
std::ifstream fin(fileName);
if (fin.is_open()) {
T temp;
while (fin >> temp) {
v.push_back(temp);
}
v.reverse();
fin.close();
}
}
Vector<int> carriagesRearrangement_queue
版权声明:本文为CoderMaximum原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。