Tarun
BAN USER
Comments (2)
Reputation 20
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
1
of 1 vote
#include<iostream>
#include<vector>
#include<string>
using namespace std;
string func(string s){
vector<char> v;
string s2="";
for(int i=0;i<s.size();i++){
if(s[i]==' ' || i==s.size()-1){
if(i==s.size()-1) v.push_back(s[i]);
while(v.size()){
s2=s2+v[v.size()-1];
v.pop_back();
}
s2=s2+' ';
}
else
v.push_back(s[i]);
}
return s2;
}
int main(){
string s = "We will rock you !";
cout<<func(s)<<endl;
return 0;
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
It depends on the situation but in general Quicksort is one of best available. A close second in Mergesort.
- Tarun March 11, 2016Src:h$$p://stackoverflow.com/questions/70402/why-is-quicksort-better-than-mergesort