selection problem/排序算法
来源:互联网 发布:淘宝店刚开始卖什么好 编辑:程序博客网 时间:2024/06/11 17:20
Suppose you have a group of n numbers and would like to determine the kth largest. This is known as the selection problem.
1. bubble sort/冒泡法
One way to solve this problem would be to read the n numbers into an array, sort the array in decreasing order by somesimple algorithm such as bubblesort, and then return the element in position k.
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main() {
// 100 random data
int src_data[100];
printf("Display the sourc data\n");
srand(time(NULL)); // random seed
for (int i = 0; i < 100; i++)
{
src_data[i] = 1+(int)99 * rand() / (RAND_MAX + 1); // random data from 1 to 100
printf("%d\n", src_data[i]);
}
// bubble sort approach
int temp;
for(int m=0;m<100;m++)
for (int n = 0; n < 100-m-1; n++) {
if (src_data[n] > src_data[n+1]) {
temp = src_data[n];
src_data[n] = src_data[n+1];
src_data[n+1] = temp;
}
}
printf("\nDisplay the bubble sort data\n");
for (int k = 0; k < 100; k++)
printf("%d\n", src_data[k]);
return -1;
}
- selection problem/排序算法
- Activity Selection Problem 贪心算法
- 算法--选择排序 Selection Sort
- C#排序算法(二)选择排序(Selection)
- 经典排序算法 - 选择排序Selection sort
- 经典排序算法 - 选择排序Selection sort
- 经典排序算法 - 选择排序Selection sort
- 排序算法-选择排序 Selection Sort
- 经典排序算法 - 选择排序Selection sort
- 排序算法---选择排序(Selection Sort)
- Selection Problem
- 选择排序(selection sort)算法实现
- 选择排序算法——Selection Sort
- 选择排序(selection sort)算法实现
- 选择排序算法(Selection Sort)
- 【排序算法】 选择排序 selection sort(选择类排序)
- 基础排序算法 – 选择排序Selection sort
- 排序算法——选择排序(Selection Sort)
- 上机练习题——接口(课堂练习2)
- C# ref,值传递转换为引用传递
- Java 多线程学习笔记3
- J
- cadence vmanager(十) vplan与vmanager结合使用的例子
- selection problem/排序算法
- 剑指offer 构造乘积数组
- Ubuntu主机安装ssh相关服务步骤
- HDOJ2028【简单递归】
- STL容器学习总结(二)
- linux下批量删除空文件(大小等于0的文件)的方法
- Python 中各种imread函数的区别与联系
- JAVA面试题
- ######springmvc中方法返回值为String时@responseBody不能返回json对象。