String sort question

Nishant is a very naughty boy in Launchpad Batch. One day he was playing with strings, and randomly shuffled them all. Your task is to help Nishant Sort all the strings ( lexicographically ) but if a string is present completely as a prefix in another string, then string with longer length should come first. Eg bat, batman are 2 strings and the string bat is present as a prefix in Batman - then sorted order should have - Batman, bat.
Sample Input

3
bat
apple
batman

Sample Output

apple
batman
bat
The code written by me

using namespace std;

bool compare(string a,string b){

if(a.find(b)){
	return a<b;
}
else  if(b.find(a)){
	return a>b;
}
else return a<b;

}

void sort(string a [],int n,bool compare){

for(int itr=1;itr<n;itr++){
for(int i=0;i<=n-itr-1;i++){
if(a[i]>a[i+1]){

 		swap(a[i],a[i+1]);	
 }}
 }
for(int i=0;i<n;i++){
	cout<<a[i]<<endl;
}

}
int main() {

string a[1000];

 int n;

cin>>n;

cin.get();

for(int i=0;i<n;i++){

	getline(cin,a[i]);

}

sort(a,n,compare);

return 0;

}

plz tell the mistake as I am not getting correct output

you should only return a < b. if a is not a prefix of b otherwise you need to return the bigger

@keshavgupta0103
i know that but i am unable to make a correct logic and you plz check my code and edit it accordingly and sent it.
It would be really beneficial for me.

can you share your code through ide.codingblocks.com

#include<iostream
using namespace std;

bool compare(string a,string b){

if(a.find(b)){
	return a<b;
}
else  if(b.find(a)){
	return a>b;
}
else return a<b;

}

void sort(string a [],int n,bool compare){

for(int itr=1;itr<n;itr++){
for(int i=0;i<=n-itr-1;i++){
if(a[i]>a[i+1]){

 		swap(a[i],a[i+1]);	
 }}
 }
for(int i=0;i<n;i++){
	cout<<a[i]<<endl;
}

}
int main() {

string a[1000];

 int n;

cin>>n;

cin.get();

for(int i=0;i<n;i++){

	getline(cin,a[i]);

}

sort(a,n,compare);

return 0;


}

can u tell how to share code through code blocks ide

open ide.codingblocks.com
paste your code
click on file then click on save
a dialog box will appear click on save
now you can share your code with using the link

@keshavgupta0103

you have to use the inbuilt sort function
Corrected code

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.