[ Pobierz całość w formacie PDF ]
.Note that each type of adapter has a default container that it’s built upon, and this default is the most sensible implementation, so in most cases you won’t need to concern yourself with the underlying implementation.CommentThe following example shows stack implemented in the three possible ways: the default (which uses deque), with a vector and with a list:Comment//: C07:Stack1.cpp// Demonstrates the STL stack//{L}./TestSuite/Test#include#include#include#include#include#includeusing namespace std;// Default: deque:typedef stack Stack1;// Use a vector:typedef stack Stack2;// Use a list:typedef stack Stack3;int main() {ifstream in("Stack1.cpp");Stack1 textlines; // Try the different versions// Read file and store lines in the stack:string line;while(getline(in, line))textlines.push(line + "\n");// Print lines from the stack and pop them:while(!textlines.empty()) {cout
[ Pobierz całość w formacie PDF ]