c-四个数排序,这个程序有什么问题?

问题描述

四个数排序,这个程序有什么问题?
#include

using namespace std;

void swap(int& a int& b);

int main()
{
int a b c d;
cin >> a >> b >> c >> d;
if (b < a) swap(b a);
if (c < b) swap(c b);
if (d < c) swap(d c);
if (b < a) swap(b a);
if (c < b) swap(c b);
if (b < a) swap(b a);
cout << a << b << c << d;
}

void swap(int& a int& b)
{
int c = a;
a = b;
b = c;
}

解决方案

这就是冒泡排序嘛,当然这样写有点傻,可以用循环实现。

解决方案二:
没啥,先说能遇到了什么问题

解决方案三:
如果你们老师没有限定非得用数组或者循环的话,应该没问题。

时间: 2024-08-12 19:26:14

c-四个数排序,这个程序有什么问题?的相关文章

c++-用冒泡排序法对10个数排序,怎么错了啊?

问题描述 用冒泡排序法对10个数排序,怎么错了啊? #includeusing namespace std;int main(){ int a[10]ij t; cout << ""input 10 numbers:"" << endl; for (i = 0; i < 10; i++) cin >> a[i]; cout << endl; for (j = 0; j < 9;j++) for (i = 0

c++-用C++写一个排序的程序

问题描述 用C++写一个排序的程序 题目的意思是 你从键盘录入一系列数,然后你把他按顺序排好,用数组,但要建立类,C++写 解决方案 #include <iostream> using namespace std; class A { public: void print(int* pData, int count){ for (int i = 0; i< count; i++) { cout << pData[i] << " "; } cou

排列组合 算法-问一道排列组合题 一组数据 随机选四个数组成四元组,请问总共有多少个偶排列,

问题描述 问一道排列组合题 一组数据 随机选四个数组成四元组,请问总共有多少个偶排列, 问一道排列组合题 一组数据 随机选四个数组成四元组,请问总共有多少个偶排列,数组例如(±1.6,±1,±0.6,0) 七选四 解决方案 840-------偶排列数:420 程序 public class test { static void f(double[] a,int n,String v){ if(n==a.length){ System.out.println(v); }else{ f(a,n+1

请问怎样怎样将三个数排序.最简单的方法.

问题描述 请问怎样怎样将三个数排序.最简单的方法. 解决方案 解决方案二:System.Collections.ArrayListtest=newSystem.Collections.ArrayList();test.Add(2);test.Add(1);test.Add(3);test.Sort(); 解决方案三:用list<int>_list=newlist<int>好点!_list.sort();解决方案四:System.Collections.ArrayListtest=n

数组数据排序的程序例子

数组数据排序的程序例子 <% ''*** build example array to show that this thing can sort ''*** alpha-numeric arrays Dim MyArray MyArray = Array(1,5,"shawn","says","hello"2m骺噃嶤123,12,98) MyArray = Sort(MyArray) For I = 0 to Ubound(MyArray

C#的四种排序算法

排序|算法 本文介绍了C#的四种排序算法:冒泡排序.选择排序.插入排序和希尔排序 冒泡排序 using System: namespace BubbleSorter { public class BubbleSorter { public void Sort(int [] list) { int i,j,temp: bool done=false: j=1: while((j<list.Length)&&(!done)) { done=true: for(i=0:i<list.

经典算法-C#四种排序算法

排序|算法 本文介绍了C#的四种排序算法:冒泡排序.选择排序.插入排序和希尔排序 冒泡排序 using System: namespace BubbleSorter { public class BubbleSorter { public void Sort(int [] list) { int i,j,temp: bool done=false: j=1: while((j<list.Length)&&(!done)) { done=true: for(i=0:i<list.

C#的四种排序算法:冒泡排序、选择排序、插入排序和希尔排序

插入|排序|算法 本文介绍了C#的四种排序算法:冒泡排序.选择排序.插入排序和希尔排序 冒泡排序 using System: namespace BubbleSorter { public class BubbleSorter { public void Sort(int [] list) { int i,j,temp: bool done=false: j=1: while((j<list.Length)&&(!done)) { done=true: for(i=0:i<li

c++-C++多线程外部排序的程序报错 bad allocaltion

问题描述 C++多线程外部排序的程序报错 bad allocaltion http://www.cnblogs.com/Jedimaster/archive/2013/11/17/3427761.html 按照这个网页给的方法,写多线程的外部排序算法.我先用第一个产生数据的算法 产生了429496729个int大小的数据.整个文件大概有1.59G这么大.然后分成4个进程,来处理数据.在main函数中,将iNumLocalItems设置为 20 * 1024 * 1024以及更小没有任何错误,但是