sortwlen.cpp

来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C++ 代码 · 共 41 行

CPP
41
字号
#include <iostream>#include <fstream>#include <string>using namespace std;#include "tvector.h"#include "prompt.h"#include "sortall.h"// illustrates templates, read words, sort words, print wordstemplate <class Type>void Print(const tvector<Type>& list, int first, int last)// post: list[first]..list[last] printed, one per line{    int k;    for(k=first; k <= last; k++)    {   cout << list[k] << endl;    }}int main(){    tvector<string> wordList;    tvector<int>    lengthList;    string filename = PromptString("filename: ");    string word;    ifstream input(filename.c_str());        while (input >> word)    {   wordList.push_back(word);        lengthList.push_back(word.length());    }    SelectSort(wordList,wordList.size());    SelectSort(lengthList,lengthList.size());        Print(wordList,wordList.size()-5,wordList.size()-1);    Print(lengthList,lengthList.size()-5,lengthList.size()-1);        return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?