1 Replies - 2672 Views - Last Post: 13 October 2012 - 06:06 AM Rate Topic: -----

#1 yaksha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-October 12

inserting structures in between queue using dqueue

Posted 13 October 2012 - 02:43 AM

in this code can we use structures as to insert instead of integers? if so how the assignment will be , can some someone help to modify my code using structures instead of integer value



#include <iostream>
#include <deque>
#include <vector>
using namespace std;

int main ()
{
  deque<int> mydeque;
  deque<int>::iterator it;

  // set some initial values:
  for (int i=1; i<6; i++) mydeque.push_back(i); // 1 2 3 4 5

  it = mydeque.begin();
  ++it;

  it = mydeque.insert (it,30);                  // 1 10 2 3 4 5
  // "it" now points to the newly inserted 10

  mydeque.insert (it,2,22);                     // 1 20 20 10 2 3 4 5
  // "it" no longer valid!

  it = mydeque.begin()+2;

  vector<int> myvector (2,35);
  mydeque.insert (it,myvector.begin(),myvector.end());
                                                // 1 20 30 30 20 10 2 3 4 5

  cout << "mydeque contains:";
  for (it=mydeque.begin(); it<mydeque.end(); ++it)
    cout << " " << *it;
  cout << endl;

  return 0;
}

This post has been edited by jimblumberg: 13 October 2012 - 06:03 AM
Reason for edit:: Added missing Code Tags, Please learn to use them.


Is This A Good Question/Topic? 0
  • +

Replies To: inserting structures in between queue using dqueue

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4140
  • View blog
  • Posts: 12,891
  • Joined: 25-December 09

Re: inserting structures in between queue using dqueue

Posted 13 October 2012 - 06:06 AM

Quote

in this code can we use structures as to insert instead of integers?

Since a std::queue can use any type, yes you can modify the program to insert your structures.

Quote

can some someone help to modify my code using structures instead of integer value

Show us what you have tried. This should be a very easy conversion so give it a try and if you have specific problems ask specific questions.

Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1