Use generic deque to store integers,CREATE,SHORT,COPIE

Started by dhilipkumar, Dec 04, 2008, 06:11 PM

Previous topic - Next topic

dhilipkumar




#include <iostream>
#include <cassert>
#include <deque>
#include <algorithm>  // For find
using namespace std;


int main()
{
  int x[5] = {1, 2, 3, 4, 5};

  deque<int> deque1(&x[0], &x[5]);

  // Search for the first occurrence of the letter e:
  deque<int>::iterator where = find(deque1.begin(), deque1.end(), 1);

  cout << *where << endl;
  return 0;
}

/*
1

*/


Use generic deque to store chars


#include <iostream>
#include <cassert>
#include <deque>
#include <algorithm>  // For find
using namespace std;


int main()
{
  char x[5] = {'a', 'r', 'e', 'q', 't'};

  deque<char> deque1(&x[0], &x[5]);

  // Search for the first occurrence of the letter e:
  deque<char>::iterator where = find(deque1.begin(), deque1.end(), 'e');

  assert (*where == 'e' );
  cout << "Ok." << endl;
  return 0;
}
/*
Ok.

*/
       

dhilipkumar

Use generic deque to store strings



#include <iostream>
#include <cassert>
#include <deque>
#include <algorithm>  // For find
using namespace std;


int main()
{
  string x[5] = {"1234", "2345", "3456","4567", "5678"};

  deque<string> deque1(&x[0], &x[5]);

  // Search for the first occurrence of the letter e:
  deque<string>::iterator i;

  cout.precision(10);

  for (i = deque1.begin(); i != deque1.end(); ++i)
    cout << *i << endl;
  return 0;
}

/*
1234
2345
3456
4567
5678

*/       
 

Initialize deque with 26 copies of the letter x



#include <iostream>
#include <cassert>
#include <list>
#include <deque>
#include <algorithm>  // For merge
using namespace std;

int main()
{
  // Initialize deque1 with 26 copies of the letter x:
  deque<char> deque1(26, 'x');

  deque<char>::iterator i;

  cout.precision(10);

  for (i = deque1.begin(); i != deque1.end(); ++i)
    cout << *i << endl;

  return 0;
}

/*
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x
x

*/