自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(9)
  • 资源 (3)
  • 收藏
  • 关注

转载 “基数排序”应用之数组中缺失的数字

首先看看题目要求: 给定一个无序的整数数组,怎么找到第一个大于0,并且不在此数组的整数。比如[1,2,0]返回3,[3,4,-1,1]返回2,[1, 5, 3, 4, 2]返回6,[100, 3, 2, 1, 6,8, 5]返回4。要求使用O(1)空间和O(n)时间。  我们不难发现使用“基数排序”正好可以用来解决这道题目。 以{1, 3, 6, -100, 2}为例来简介这种解法:

2014-11-07 23:59:38 668

原创 归并排序

package com.sort; public class MergeSort { public static void main(String[] args) { int[] a=new int[]{-6,5,4,3,-2,1}; mergeSort(a,0,a.length-1); for(int array:a){ System.out.println(array);

2014-11-07 23:34:52 1446

原创 希尔排序

package com.sort; public class ShellSort { static void shellsort3(int a[], int n) { int i, j, gap; for (gap = n / 2; gap > 0; gap /= 2) for (i = gap; i < n; i++) for (j = i - gap; j >=

2014-11-07 22:46:12 1458

原创 简单选择排序

package com.sort; public class SelectSort { public static void main(String[] args) { int[] a = new int[]{6,5,4,3,2,1}; selectSort(a); for(int array:a){ System.out.println(array); } }

2014-11-07 02:35:30 538

原创 交换排序之快速排序

package com.sort; public class QuickSort { public static void main(String[] args) { int[] a = new int[]{6,5,4,3,2,1}; quickSort(a,0,a.length-1); for(int array:a){ System.out.println(array);

2014-11-07 02:34:04 544

原创 交换排序之冒泡排序

package com.sort; //冒泡排序:O(n^) public class BubbleSort { public static void bubbleSort(int[] a) { for (int i = 1; i < a.length; i++) {// 表示次数 int j = a.length - 1; while (j >= i) { if (

2014-11-07 02:32:25 573

原创 计数排序

package com.sort; //计数排序 public class CountSort { //适用于排序元素在一个数值范围内 //一下以公司员工年龄为元素排序(Age:18-70) public static void main(String[] args) { int[] a = new int[]{26,25,24,23,23,26,25,24,23,26,25,24,

2014-11-07 02:31:59 1409

原创 堆排序

package com.sort; public class HeapSort { public static void main(String[] args) { HeapSort heapSortObj = new HeapSort(); int[] a = new int[] { 4, 3, 6, 5, 4, 3, 2, 1 }; MinHeap maxHeap = heap

2014-11-07 02:30:59 1508

原创 插入排序之直接插入排序

package com.sort; public class InsertSort { public static void insertSort(int[] a){ for(int i=1; i<a.length; i++){ int j = i; int key = a[j];//暂存到key中 while(j>0 && key<a[j-1]){//不断往后覆盖

2014-11-07 02:28:58 501

C语言成绩管理

完成某学期的学生成绩的管理。 问题描述:    完成学生成绩管理,具体要求如下:    1.输入一个班n名学生(n30),m门课程(m8)的成绩,做成文件score.in,    要求有良好的输入界面;    2.score.in中读入该班成绩,计算出每位学生总成绩、平均成绩;    3.按总成绩降序排列;    4.根据学号或姓名查找某学生成绩;    5.在屏幕上设计表格,显示该班成绩单(包括单科成绩、总成绩、平均成绩);    6.将经过排序的成绩及总成绩、平均成绩输出到文件score.out中。 要求将程序分成几个独立的模块,组成几个源程序,然后连接成一个可运行目标程序,运行得到结果。

2013-03-29

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除