5

c++小白对于冒泡排序出现问题的提问

 2 years ago
source link: https://www.oschina.net/question/5553824_2324891
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

c++小白对于冒泡排序出现问题的提问

osc_16699020 发布于 昨天 15:47

#include<iostream>
using namespace std;
int main(){
    double a[100];
    int i=0,j=0;
    int N,x;
    const int P='999';//想要实现特定结束符,不去输入数字个数作为结束依据。
    cout<<"请输入数字"<<endl;
    cin>>x;
    while(x!=P){
        a[i]=x;
        i++;
        }
        N=i;    //输入部分有问题
    for(i=0;i<N-1;i++){
        for(j=0;j<N-1-i;j++){
            int tmp;
            if(a[j]>a[j+1]){
                tmp=a[j];
                a[j]=a[j+1];
                a[j+1]=tmp;
            }
        }
    }
    for(i=0;i<N;i++){
        cout<<a[i]<<"  ";
    }
    cout<<endl;
    return 0;
}


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK