- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
list.c
资源名称:leda.tar.gz [点击查看]
上传用户:gzelex
上传日期:2007-01-07
资源大小:707k
文件大小:1k
源码类别:
数值算法/人工智能
开发平台:
MultiPlatform
- #include <LEDA/list.h>
- #include <LEDA/stream.h>
- int cmp_inv(const string& x, const string& y) { return compare(y,x); }
- int cmp_length(const string& x, const string& y)
- { return x.length() - y.length(); }
- int ord(const string& x) { return (x.length() > 0) ? int(x[0]) : 0;}
- void upper_case(string& x)
- { int d = 'A' - 'a';
- for(int i=0; i<x.length(); i++)
- if (x[i] >= 'a' && x[i] <= 'z') x[i] += d;
- }
- main()
- {
- string fname = read_string("file: ");
- list<string> L;
- if (fname == "cin")
- L.read("L = ");
- else
- L.read(file_istream(fname),EOF);
- L.permute();
- // sort lexicographically
- L.sort(); // compare(string,string) used
- L.print("sorted lexicographically:n",'n');
- newline;
- newline;
- // sort decreasing
- L.sort(cmp_inv);
- L.print("sorted decrasing:n",'n');
- newline;
- newline;
- // sort by length
- L.sort(cmp_length);
- L.print("sorted by length:n",'n');
- newline;
- newline;
- // bucket_sort by first character
- L.bucket_sort(0,255,ord);
- L.print("sorted by s[0]:n",'n');
- newline;
- newline;
- // turn characters to upper case
- L.apply(upper_case);
- L.print("upper case:n",'n');
- newline;
- newline;
- cout << "used memory = " << used_memory() << " bytesn";
- return 0;
- }