ADVERTISEMENT
ADVERTISEMENT

Home » C++ STL

Push and print elements in an integer deque in C++ STL

C++ STL deque: Here, we are implementing a program in which we are declaring an integer deque, pushing the elements and printing the elements.
Submitted by IncludeHelp, on June 18, 2019

In this example, we are declaring an integer deque and pushing the elements using a for loop with the counter starting value from 1 to 5 and then printing the value separated by space.

Code:

#include <iostream>
#include <deque> //for deque
using namespace std;

int main()
{
    // deque  for integer elements
    deque<int> d1;

    // adding 5 elements
    for (int i = 1; i <= 5; ++i) {
        d1.push_back(i);
    }

    // print all elements
    cout << "deque elements are: ";
    for (int i = 0; i < d1.size(); ++i) {
        cout << d1[i] << ' ';
    }
    cout << endl;

    return 0;
}

Output

deque elements are: 1 2 3 4 5
ADVERTISEMENT


ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.