Skip to content

Instantly share code, notes, and snippets.

@daemonfire300
Created February 2, 2013 13:24
Show Gist options
  • Save daemonfire300/4697356 to your computer and use it in GitHub Desktop.
Save daemonfire300/4697356 to your computer and use it in GitHub Desktop.
// Blatt12.2.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//
#include "stdafx.h" // unter linux einfach entfernen
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <set>
using namespace std;
bool isPositive(int x)
{
return (x >= 0);
}
void ref_abs(int& x)
{
x = abs(x);
}
int _tmain(int argc, _TCHAR* argv[]) // bitte an Linux anpassen das hier ist nur mit Visual Studio 2012 verwendbar
{
vector<int> pos = vector<int>();
vector<int> neg = vector<int>();
vector<int> mixed = vector<int>();
for(int i = 1; i <= 10; i++)
{
pos.push_back(i*10);
neg.push_back(i*10*(-1));
}
vector<int>::iterator it_pos;
vector<int>::reverse_iterator it_neg;
for(it_pos = pos.begin(), it_neg = neg.rbegin(); it_pos != pos.end(), it_neg != neg.rend(); it_pos++, it_neg++)
{
mixed.push_back(*it_pos);
mixed.push_back(*it_neg);
}
int pos_count = count_if(mixed.begin(), mixed.end(), isPositive);
cout << pos_count << "\t : Positive Werte, guess what es sind immer 10, diese Aufgabe ist ein totaler Stuss -.-" << endl << endl;
for_each(mixed.begin(), mixed.end(), ref_abs);
pos_count = count_if(mixed.begin(), mixed.end(), isPositive);
cout << pos_count << "\t : Positive Werte" << endl;
set<int> int_set = set<int>(mixed.begin(), mixed.end());
multiset<int> m_int_set = multiset<int>(mixed.begin(), mixed.end());
cout << endl;
cout << "Größe int_set: " << int_set.size() << endl;
cout << "Größe m_int_set: " << m_int_set.size() << endl; // Suprise, suprise, multiset hat genauso so viele Element wie mixed wowowowoww..... -.-
system("PAUSE");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment