/*
Fun WIth Vectors
by Bruce Elenbogen
Writing some functions with Vectors
*/
#include <iostream>
#include <algorithm> // for sort, next_permutation
#include <vector>
#include <string>
using namespace std;
template<class T>
void printVec(vector<T> collection){
/*
for (unsigned int i = 0; i < collection.size(); i++)
cout << collection[i] << endl;
*/
for(auto item : collection)
cout << item ;
}
int main(){
vector<string> words = { "cat", "dog", "fish", "horse", "bird", "dragon", "gopher", "sheep" };
vector<char> characters = { 'A', 'C', 'M', 'Y' };
vector<int> nums(10); // makes a vector of 10 values 0 - 9
vector<double> reals(10, 2.0); // makes a vector of size 10 al set to 2.0
/*
to add an element to a vector you can use insert(iterator);
to remove an element from a vector you can use delete(iterator);
clear(); removes everything from the vector
*/
string word;
int count = 0;
//int howMany;
//cout << "enter how many strings to add : ";
//cin >> howMany;
//words.resize(howMany); // allocates space for resize number of elements
/*cout << "enter a string to store and stop to stop ";
cin >> word;
while (word != "stop") {
words.push_back(word);
cout << "enter a string to store and stop to stop ";
cin >> word;
}*/
cout << "before sorted:\n";
//printVec(words);
sort(words.begin(), words.end());
cout << "after sorting:\n";
cout << "the first word is : "<< *words.begin() << endl;
//cout << "the first address is : " << (int) words.begin() << endl;
//printVec(words);
do{
cout << count++ << " ";
printVec(characters);
cout << endl;
} while (next_permutation(characters.begin(), characters.end()-2));
return 0;
}
/*
ABCDE
BACED
EABCD
ABCDE
ABCED
ABDCE
ABDEC
ABE
:
EDCBA
*/
Fun With Vectors
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.