The list container corresponds to a list of common data structures. The list container supports fast random inserts, deletes, but does not support fast random access elements; This is not the same as the vector container, vector containers do not support fast random inserts, deletes, but support fast with
Machine Access element.
The properties of the list container determine that the insertion order can be implemented without additional storage space, and that the time complexity is O (n^2), the same as the time complexity of the array implementation of the fast row.
File processing in C + + is also convenient, just declare a FStream object, and then the same as the standard device input.
#include <iostream>
#include <fstream>
#include <list>
using namespace std;
Reading data from the file, by inserting the sort, completes the list from small to large stable sort.
int main ()
{
list<int>mylist;
Ifstream input;
Input.open ("In.txt");
int ele;
while (Input>>ele)
{
if (input.eof ()) break
;
if (Input.bad ()) break
;
List<int>::iterator Iter=mylist.begin ();
while (Iter!=mylist.end () && (*iter) <=ele)
++iter;
Mylist.insert (Iter,ele);
}
Input.close ();
Ofstream output;
Output.open ("OUT.txt");
For (List<int>::iterator Iter=mylist.begin (); Iter!=mylist.end (); ++iter)
{
cout<< (*iter) <<endl;
output<< (*iter) << " ";
}
Output.close ();
return 0;
}