C++ STL, a very simple deque code example

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Creating a very simple C++ deque in C++ programming

To show: How to create a very simple C++ deque in C++ programming

 

// C++ STL simple deque example

#include <iostream>

#include <deque>

using namespace std;

 

int main(void)

{

// deque container for floating-point elements

deque<double> elem, elem1;

unsigned int i;

 

// insert the elements each at the front

cout<<"push_front()"<<endl;

cout<<"elem deque: ";

for(i=1; i<=10; ++i)

// insert at the front

elem.push_front(i*(1.2));

 

// print all elements separated by a space

for(i=0; i<elem.size(); ++i)

cout<<elem[i]<<' ';

cout<<endl;

 

// insert the elements each at the back

cout<<"\npush_back()"<<endl;

cout<<"elem1 deque: ";

// insert at the back

for(i=1; i<=10; ++i)

elem1.push_back(i*(1.2));

 

// print all elements separated by a space

for(i=0; i<elem1.size(); ++i)

cout<<elem1[i]<<' ';

cout<<endl;

return 0;

}

 

Output examples:

 

push_front()

elem deque: 12 10.8 9.6 8.4 7.2 6 4.8 3.6 2.4 1.2

push_back()

elem1 deque: 1.2 2.4 3.6 4.8 6 7.2 8.4 9.6 10.8 12

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index