首页 > 其他分享 >随机数排序

随机数排序

时间:2023-06-07 17:12:08浏览次数:27  
标签:std main 排序 int 随机数 include

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(int argc, char** argv) {
	int a[10];
	int m;
	srand(time(0));
	for(int i=0;i<10;i++){
		m=rand()%1000;
		cout<<m<<"   ";
		a[i]=m;
	}
	int o;
	for(int j=0;j<10;j++){
		for(int l=j;l<10;l++){
			if(a[j]>a[l]){
				o=a[j];
				a[j]=a[l];
				a[l]=o;
			}
		}
	}
	for(int i=0;i<10;i++){
		cout<<a[i]<<endl;
	}
	return 0;
}

  

标签:std,main,排序,int,随机数,include
From: https://www.cnblogs.com/wangyueshuo/p/17463944.html

相关文章

  • 产生随机数 random.seed()
     importrandom#随机函数前不要seed()方法print('随机数0:',random.random())print('随机数000:',random.random())#随机数不一样#当seed()没有参数时,每次生成的随机数是不一样的random.seed()print('++++++++++seed()随机数:',random.random())random.seed()pr......
  • 快速排序模板
    思路快排基本思路应该就是二分+递归,从两侧同时(实则先从右往左)往中间找,同时和参变量对比,发现位置颠倒后交换位置,然后通过二分将其一块一块的分割开,直到分割到一个元素位置,即完成了快排。代码#include<bits/stdc++.h>usingnamespacestd;inta[101],n;voidquicksort(intleft......
  • 一文理清排序算法中的直接插入、快排和希尔排序的区别
    前言在上一篇文章中,给大家介绍了冒泡排序和选择排序,这两种算法都是排序算法。实际上排序算法还有插入、希尔、快速排序等,接下来我们就来学习一下这几种排序算法。全文大约【5400】字,不说废话,只讲可以让你学到技术、明白原理的纯干货!本文带有丰富的案例及配图视频,让你更好地理......
  • 摆动排序
    #define_CRT_SECURE_NO_WARNINGS1#include<stdio.h>intmain(){ floatarr[20],h; inti,t=0; charc; printf("pleaseputnumbers:\n"); for(i=0;i<10;i++) { scanf("%f%c",&arr[i],&c); if(c=='......
  • 算法 in Golang:Quicksort(快速排序)
    算法inGolang:Quicksort(快速排序)Quicksort(快速排序)快速排序O(nlog2^n),比选择排序要快O(n²)在日常生活中经常使用使用了D&C策略(分而治之)使用Quicksort排序数组不需要排序的数组(也就是BaseCase基线条件):[],空数组[s],单元素数组很容易排序的数组:[a,b],两......
  • 数据结构与算法分析(Java语言描述)(13)—— 原地堆排序
    packagecom.algorithm.sort;publicclassHeapSortInPlace{privateHeapSortInPlace(){}publicstaticvoidsort(Integer[]arr){intn=arr.length;//注意:我们堆的索引是从0开始的//从(最后一个元素的索引-1)/2开始......
  • 数据结构与算法分析(Java语言描述)(10)—— (三向切分)快速排序
    QuickSortThreeWays.javapackagecom.algorithm.sort;publicclassQuickSortThreeWays{privateQuickSortThreeWays(){}publicstaticvoidsort(Integer[]arr){intn=arr.length;sort(arr,0,n-1);}publicstatic......
  • 数据结构与算法分析(Java语言描述)(9)—— (双轴)快速排序
    QuickSortTwoWays.javapackagecom.algorithm.sort;publicclassQuickSortTwoWays{privateQuickSortTwoWays(){}publicstaticvoidsort(Integer[]arr){intn=arr.length;sort(arr,0,n-1);}//递归使用快速排序,对arr......
  • 数据结构与算法分析(Java语言描述)(8)—— (随机)快速排序
    伪代码foreach(unsorted)partitionrandomlyselectpivot,swapwithfirstelementstoreIndex=pivotIndex+1fori=pivotIndex+1torightmostIndexifelement[i]<element[pivot]swap(i,storeIndex);storeIndex++swap(pivot,storeIndex......
  • 数据结构与算法分析(Java语言描述)(7)—— 快速排序
    伪代码foreach(unsorted)partitionsetfirstelementaspivotstoreIndex=pivotIndex+1fori=pivotIndex+1torightmostIndexifelement[i]<element[pivot]swap(i,storeIndex);storeIndex++swap(pivot,storeIndex-1)QuickSort.javap......