请问为什么对s字符串进行冒泡排序后会出现错误?后面正倒序输出没有错误,已经调试过哪里了

img

img

img


#include <iostream>
using namespace std;
#include <string>
#include <sstream>
#include <cstring>
#include <exception>
void sort(string x,int n);
int main()
{
    string s;//判断是否为相同的数字 
    cin>>s;
    int n=s.length();
    bool judge=false;
    for(int i=0;i<n-1;i++)
    {
        if(s[i]!= s[i+1])
        {
            judge = true;
            break;
        }
    }
//     std::istringstream iss (text);
    if(judge)
    {
        char temp=0;//对s字符串进行冒泡排序 
        for(int i=0;i<n;i++)
        {
            for(int j=i;j<n-i;j++)
            {
                if(s[j]-'0' > s[j+1]-'0')
                {
                    temp = s[j];
                    s[j] = s[j+1];
                    s[j+1] = temp;
                    cout<<s[j]<<" "<<s[j+1]<<endl; 
                }
            }
        }
        int a=0,b=0;
        for(int i=0;i<n;i++)//分别正序和倒序输出s字符串 
        {
            a = a *10 + (s[i] - '0');
        }
        for(int i=n-1;i>=0;i--)
        {
            b = b * 10 + (s[i]-'0');
        }
        cout<<a<<endl<<b<<endl;
    }
    else
    {
        cout<<"false";
    }
}


为什么会报错?报错是什么意思?如何解决?

冒泡排序写错了

建议桶排