I am writing a program that will rotate the letters in the vector CharList depending on the sign of the integer. I need help with the bubble sort (my RotateLetters function.) This is what I have so far.
Thanks in advance. :-)
Code:
#include <iostream>
#include <vector>
#include <cmath> //abs()
using namespace std;
void RotateLetters (vector <char> & CharList, int NumPositions);
int main (void)
{
vector <char> Alphabet (26);
for (int cnt = 0; cnt < 26; cnt++)
Alphabet [cnt] = char (cnt + 'A');
cout << "How many positions do you intend to rotate this alphabet list? "
<< " '-' means rotate upward; otherwise downward." << endl;
int Positions;
cin >> Positions;
RotateLetters (Alphabet, Positions);
for (cnt = 0; cnt < Alphabet.size(); cnt++)
cout << Alphabet[cnt];
cout << endl;
return 0;
}
void RotateLetters (vector <char> & CharList, int NumPositions)
{
int pairs;
int index;
for (pairs = CharList.size() - 1; pairs > 0; pairs--)
for (index = 0; index < pairs; index++)
if (CharList[index] > CharList[index + 1])
{
int temp;
temp = CharList[index];
CharList[index] = CharList[index + 1];
CharList[index + 1] = temp;
}
}