#include <iostream>
#include <string>
#include <cctype>
#include <iomanip>
#define N 36
using namespace std;
string EraseWhiteSpaces(string &str_nospaces)
{
int i;
for (int i=0;i<str_nospaces.length();i++)
{
if (str_nospaces[i]==' '||(str_nospaces[i]=='\t'))
{
str_nospaces.erase(i,1);
i--;
}
}
return str_nospaces;
}
string ConvertToLowerCase(string &str_lowercase)
{
int i;
for (i=0;i<str_lowercase.length();i++)
str_lowercase[i]=tolower(str_lowercase[i]);
return str_lowercase;
}
void SortedFrequences(int frequences[],char chars[])
{
int i,j,tmp1;
char tmp2;
for (i=0;i<N;i++)
{
for (j=i+1;j<N;j++)
{ //THE PROBLEM IS HERE!!!!!!!!
if (frequences[i]<frequences[j])
{
tmp1=frequences[i];
frequences[i]=frequences[j];
frequences[j]=tmp1;
tmp2=chars[i];
chars[i]=chars[j];
chars[j]=tmp1;
}
}
}
cout<<"character: frequency:"<<endl;
for (i=0;i<N;i++)
{
if (frequences[i]==0)
break;
cout<<chars[i]<<":"<<frequences[i]<<endl;
}
}
int main()
{
int i,k=0,l=0,j;
string str,fstr="";
char xaraktires[N];
int suxnotites[N]={0};
while (getline(cin,str))
{
fstr+=str;
}
EraseWhiteSpaces(fstr);
ConvertToLowerCase(fstr);
for (i=0;i<26;i++)
{
xaraktires[i]=97+k;
k++;
}
for (i=26;i<N;i++)
{
xaraktires[i]=48+l;
l++;
}
for (i=0;i<fstr.length();i++)
{
for (j=0;j<N;j++)
{
if (fstr[i]==xaraktires[j])
{
suxnotites[j]++;
break;
}
}
}
SortedFrequences(suxnotites,xaraktires);
return 0;
}
I have this bubblesort function in my code. I have two arrays, one for the characters of a string and one for their frequence. what's the problem with my code? please I have a deadline in less than two hours!