//counting sort
计数排序//参考算法导论8.2节#include#include#include#includeusing namespace std;const int
k=5;const int n=7;int a[n]={5, 5, 1, 2 , 5, 4, 1};int b[...
分类:
其他好文 时间:
2014-06-12 23:08:11
阅读次数:
237
通过阅读 java.util.Collections 学习与操作 Collections 相关算法的实现,例如 sort, search, shuffle. 以及如何实现不可变 collection,如何将普通 collection 包装成线程安全的 collection。...
分类:
其他好文 时间:
2014-06-11 06:18:18
阅读次数:
362
双向冒泡 1 package com.huang; 2 3 public class
_014_bubb_sort { 4 5 int[] b={1,2}; 6 static int
a[]={12,4,35,65,43,63,2,6,9,544,43543}; 7 pu...
分类:
编程语言 时间:
2014-06-10 21:43:40
阅读次数:
275
问题:对链表进行排序,要求时间复杂度为NlogN。归并排序。
inline ListNode* getMidle(ListNode *head){
if(NULL == head || NULL == head->next)
return head;
ListNode *pslow = head;
ListNode *pfast = head;
while (pfast->next...
分类:
其他好文 时间:
2014-06-10 17:35:56
阅读次数:
282
package chap06_Heap_Sort;import static
org.junit.Assert.*;import java.util.ArrayList;import java.util.Arrays;import
org.junit.Test;/** * 优先队列,二叉堆数组实现,...
分类:
其他好文 时间:
2014-06-10 16:40:14
阅读次数:
347
一个数组,数组元素含有3种颜色,红,白,蓝。要求将数组排序,将相同颜色排在一起,整体按照红白蓝的顺序。
这个题在日常生活中很常见。比如要将东西归类,当然这个题简化成了相同颜色就认为完全相同。
基于这个特点,可以先统计各个颜色出现的次数,然后在按照题目要求的红白蓝的顺序,依次放n个红,m个白,k个蓝,就Okay了,代码详见代码一。这个思路也就是题目下面提示的方法,这个方法需遍历2次数组,本题要求遍历一次就搞定的方法,想想这个还是有点难度的。
这个题目其实我们很容易就能联想到快排的划分上来,但是仔细一想,如果按...
分类:
其他好文 时间:
2014-06-10 15:56:14
阅读次数:
223
Sort a linked list using insertion sort. 1 /**
2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 *
ListNode *nex...
分类:
其他好文 时间:
2014-06-10 12:14:19
阅读次数:
253
以后尽量能用迭代就别用递归啊,递归只是让自己轻松了,但是却增加了电脑的负担。 package
chap06_Heap_Sort;import static org.junit.Assert.*;import java.util.Arrays;import
org.junit.Test;public ...
分类:
其他好文 时间:
2014-06-10 11:57:27
阅读次数:
252
binary search\sort\find operations
status InsertNode(Node* root, data x, Node* father)
{
if(root==NULL)
{
if(father==NULL)
Tree empty;
else
{
if(xdata)
{
father->left=new Node//inital l...
分类:
其他好文 时间:
2014-06-10 08:09:49
阅读次数:
234
题目
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.
Here, we will use the...
分类:
其他好文 时间:
2014-06-10 07:21:21
阅读次数:
261