I need a simple program to accept string vector and sort using bubble sort and display the result. While executing the program automatically terminates.
#include<bits/stdc++.h>
#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
vector<string> v2;
void Bsortchar(vector <string> &ch)
{
int i, j;
string temp[1][200];
int charLength = ch.size();
cout<<ch.size();
for(i = 0; i <= charLength; i++)
{
for (j=0; j < (charLength -1); j++)
{
if (ch[j+1] < ch[j])
{
temp[1][200] = ch[j];
ch[j] = ch[j+1];
ch[j+1]= temp[1][200];
}
}
}
return;
}
int main()
{
int charSize;
//**********************************************************
cout<<"Enter the Size of the char Vector"<<endl;
cin>>charSize;
cout<<"Enter the char Vector"<<endl;
string c;
for(int i=0;i<=charSize;i++)
{
cout<<i<<":";
getline(cin,c);
v2.push_back(c);
}
//************************************************************
Bsortchar(v2);
//***********************************************************
cout<<endl<<"The sorted character vector array is : "<<endl;
for(int i=0;i<=charSize;i++)
{
cout<<v2[i]<<" ";
}
//***********************************************************
return 0;
}
Need to accept string from the user and display the results after performing a bubble sort.