为什么没有输出啊!!!!
  • 板块学术版
  • 楼主xingjielong
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/11/21 20:27
  • 上次更新2023/11/21 22:39:48
查看原帖
为什么没有输出啊!!!!
1143897
xingjielong楼主2023/11/21 20:27

一开始是想做新型排序算法,结果不输出,难受死了

#include<bits/stdc++.h>
using namespace std;
int sn[100],n; 
stack<int> a;stack<int> b;stack<int> c;
int main(){
	cin >> n;
	for(int i=1;i<=n;i++)cin >> sn[i];
	for(int i=1;i<=n;i++)a.push(sn[i]);
	while(true){
		for(int i=1;i<=n;i++){
			if(!a.empty() && a.top() > b.top()){
				b.push(a.top());
			}else if(a.empty()){
				b.push(a.top());
			}else{
				c.push(a.top());
			}
			a.pop();
		}

		if(c.empty())break;
	}
	for(int i=1;i<=n;i++){
		sn[i]=b.top();
		b.pop();
	}
	for(int i=1;i<=n;i++)cout << sn[i] << " ";
	return 0;
}
2023/11/21 20:27
加载中...