list9-13.cpp
来自「这是关于VC++中的STL容器的资料,包括了STL容器各个类之间关系以及类的说明」· C++ 代码 · 共 41 行
CPP
41 行
// Listing9-13
// This program demonstrates the use of heap sort
#include <iostream>
#include <dirent.h> // Requires POSIX Compatibility
#include <algorithm>
#include <iterator>
#include <deque>
#include <string>
using namespace std;
void main(int Argc, char *Argv[])
{
deque<string> List;
DIR *Directory;
struct dirent *Entry;
if(Argc == 2){
ostream_iterator<string> out(cout,"\n");
Directory = opendir(Argv[1]);
if(!Directory == NULL){
Entry = readdir(Directory);
while(Entry != NULL)
{
List.push_back(string(Entry->d_name));
Entry = readdir(Directory);
}
closedir(Directory);
make_heap(List.begin(),List.end());
sort_heap(List.begin(),List.end());
copy(List.begin(),List.end(),out);
}
else{
cerr << "Bad directory.." << endl;
}
}
else{
cerr << "Usage: list9-13 DirectoryName" << endl;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?