排序后怎么输出的都是i呀?

请问为什么我这个字符串数组用函数排序不排呀,排序后怎么输出的都是i呀?


#include 
#include 
#include 
using namespace std;
void strsort(string x[],int n);
int main()
{
    int n;
    string x[]={"i","love","my","mom"};
    n=sizeof(x)/sizeof(x[0]);
    cout<<"before"<for(int i=0;i"after sort"<strsort(x,n);
    for(int i=0;ireturn 0;
}
void strsort(string x[],int n)
{
    for(int i=0;i-1;i++)
    {
        for(int j=0;j1;j++)
        {
        if(x[j]1])
            {
                string temp=x[j];
                x[j+1]=x[j];
                x[j+1]=temp;
            }
        }
    }
}

img

string temp=x[j];
x[j] = x[j+1];
x[j+1]=temp;
n=sizeof(x)/sizeof(x[0]); 这是错误写法,string是不能用sizeof的

#include <iostream>
#include <string>
#include<string.h> 
using namespace std;
void strsort(string x[],int n);
int main()
{
    int n;
    string x[]={"i","love","my","mom"};
    n=4;
    cout<<"before"<<endl;
    for(int i=0;i<n;i++)
    {
        cout<<x[i]<<endl;
    }
    cout<<"after sort"<<endl;   
    strsort(x,n);
    for(int i=0;i<n;i++)
    {
        cout<<x[i]<<endl;
    }
    system("Pause");
    return 0;
}
void strsort(string x[],int n)
{
    for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<n-i-1;j++)
        {
        if(x[j]<x[j+1])
            {
                string temp=x[j];
                x[j]=x[j+1];
                x[j+1]=temp;
            }
        }
    }
}