13:05 ET Dow -154.48 at 10309.92, Nasdaq -37.61 at 2138.44, S&P -19.130 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 13:05 ET Dow -154.48 at 10309.92, Nasdaq -37.61 at 2138.44, S&P -19.1313:05 ET Dow -154.48 at 10309.92, Nasdaq -37.61 at 2138.44, S&P -19.13

.

.

Monday, March 14, 2011

Completed Bubble Sort Algorithm in C++





#include <iostream>
using namespace std;
#include "Vector.txt"

template <class T>
void Swap(T &a, T &b)
{
T temp = a;
a = b;
b = temp;

}

int main()
{

// which type of object for vector: int, double, float
int typeV;
std::cout << "What type of Vector do you want to act on?" << endl;
cin >> typeV;
switch (typeV)
{
case 1 :
{
Vector<int> Vint(0);
bool added = false;
do
{

int another;
std::cout << "Do you want to enter a number? Type '0' for 'N' and '1' for 'Y'" << endl;
cin >> another;
int toAdd;
if (another ==1)
{std::cout << "Enter an integer and press enter." << endl;
cin >> toAdd;
Vint.push_back(toAdd);
added = true;
}
else
added = false;
}
while(added==true);
printList(Vint);
// Now Sort it, then prit it
int length = Vint.size();
bool swapped = false;
do
{
for(int i=0; i < (length-1) ; i++)
{
if(Vint[i]>Vint[i+1])
{
Swap<int>(Vint[i],Vint[i+1]);
cout << "There has been a swap the new Vi & V(i+1) are" << Vint[i] << "&" << Vint[i+1] << endl;
printList(Vint);
swapped = true;
}
// end if
}
// end for
}
// close 'do' block
while(swapped);

printList(Vint);
goto pass;
}
case 2 :
{
Vector<double> Vdouble(0);
bool added = false;
do
{

int another;
std::cout << "Do you want to enter a number? Type '0' for 'N' and '1' for 'Y'" << endl;
cin >> another;
double toAdd;
if (another ==1)
{std::cout << "Enter an integer and press enter." << endl;
std::cin >> toAdd;
Vdouble.push_back(toAdd);
added = true;
}
else
added = false;
}
while(added==true);
printList(Vdouble);
// Now Sort it, then prit it
int length = Vdouble.size();
bool swapped = false;
do
{
for(int i=0; i < (length-1) ; i++)
{
if(Vdouble[i]>Vdouble[i+1])
{
Swap<double>(Vdouble[i],Vdouble[i+1]);
cout << "There has been a swap the new Vi & V(i+1) are" << Vdouble[i] << "&" << Vdouble[i+1] << endl;
printList(Vdouble);
swapped = true;
}
// end if
}
// end for
}
// close 'do' block
while(swapped);

printList(Vdouble);
goto pass;

}
case 3 :
{
Vector<float> Vfloat(0);
bool added = false;
do
{
int another;
std::cout << "Do you want to enter a number? Type '0' for 'N' and '1' for 'Y'" << endl;
std::cin >> another;
float toAdd;
if (another ==1)
{std::cout << "Enter an integer and press enter." << endl;
cin >> toAdd;
Vfloat.push_back(toAdd);
added = true;
}
else
added = false;
}
while(added==true);
printList(Vfloat);
// Now Sort it, then prit it
int length = Vfloat.size();
bool swapped = false;
do
{
for(int i=0; i < (length-1) ; i++)
{
if(Vfloat[i]>Vfloat[i+1])
{
Swap<float>(Vfloat[i],Vfloat[i+1]);
cout << "There has been a swap the new Vi & V(i+1) are" << Vfloat[i] << "&" << Vfloat[i+1] << endl;
printList(Vfloat);
swapped = true;
}
// end if
}
// end for
}
// close 'do' block
while(swapped);
printList(Vfloat);
goto pass;
}

pass:




Vector<int> V1(0);
for (int i = 0; i < 10; i++)
V1.push_back(i);
printList(V1);

V1.reserve(20);
for (int i = 10; i <20; i++)
V1.push_back(i);
printList(V1);
cout << endl;

Vector<float> V2(0);
for (int i = 0; i < 10; i++)
V2.push_back((float)i + .1f);
printList(V2);
system("PAUSE");
return 0;
}
}