當前位置:首頁 » 操作系統 » jssort源碼

jssort源碼

發布時間: 2022-05-29 17:46:46

① 為何STL的sort排序效率那麼高用的是什麼演算法

STL的sort在數據量不同的時候,他會自己選用不同的排序演算法。比如插入,快排。這些。

下面是說對STL的sort的源碼分析的,他有說到這些,你可以參考下
http://www.cnblogs.com/imAkaka/articles/2407877.html

② 請問linux下的系統命令是不是開源的 比如sort,awk等等,如果是的話,在哪可以找到源代碼

Linux是開源的,它自帶的功能強大的命令也是開源的,也就是說,我們可以獲得這些命令的源代碼並研究它。那究竟如何獲得系統的命令的源代碼呢?
命令的源代碼是一個軟體包為單元的,放在一個軟體包的源代碼中,若要下載一個命令的源代碼,就要把這個命令所屬的軟體包的源代碼都下載下來。命令的源代碼就在下載的源代碼的相關目錄內,通常是src目錄,相應的主文件名為cmd.c,其中cmd為具體的命令,如ls命令的主程序文件為ls.c。可查閱「Linux命令大全」了解Linux命令。

③ 請問一下java快速排序源代碼

快速排序:

package org.rut.util.algorithm.support;

import org.rut.util.algorithm.SortUtil;

/**
* @author treeroot
* @since 2006-2-2
* @version 1.0
*/
public class QuickSort implements SortUtil.Sort{

/* (non-Javadoc)
* @see org.rut.util.algorithm.SortUtil.Sort#sort(int[])
*/
public void sort(int[] data) {
quickSort(data,0,data.length-1);
}
private void quickSort(int[] data,int i,int j){
int pivotIndex=(i+j)/2;
//swap
SortUtil.swap(data,pivotIndex,j);

int k=partition(data,i-1,j,data[j]);
SortUtil.swap(data,k,j);
if((k-i)>1) quickSort(data,i,k-1);
if((j-k)>1) quickSort(data,k+1,j);

}
/**
* @param data
* @param i
* @param j
* @return
*/
private int partition(int[] data, int l, int r,int pivot) {
do{
while(data[++l]<pivot);
while((r!=0)&&data[--r]>pivot);
SortUtil.swap(data,l,r);
}
while(l<r);
SortUtil.swap(data,l,r);
return l;
}

}

改進後的快速排序:

package org.rut.util.algorithm.support;

import org.rut.util.algorithm.SortUtil;

/**
* @author treeroot
* @since 2006-2-2
* @version 1.0
*/
public class ImprovedQuickSort implements SortUtil.Sort {

private static int MAX_STACK_SIZE=4096;
private static int THRESHOLD=10;
/* (non-Javadoc)
* @see org.rut.util.algorithm.SortUtil.Sort#sort(int[])
*/
public void sort(int[] data) {
int[] stack=new int[MAX_STACK_SIZE];

int top=-1;
int pivot;
int pivotIndex,l,r;

stack[++top]=0;
stack[++top]=data.length-1;

while(top>0){
int j=stack[top--];
int i=stack[top--];

pivotIndex=(i+j)/2;
pivot=data[pivotIndex];

SortUtil.swap(data,pivotIndex,j);

//partition
l=i-1;
r=j;
do{
while(data[++l]<pivot);
while((r!=0)&&(data[--r]>pivot));
SortUtil.swap(data,l,r);
}
while(l<r);
SortUtil.swap(data,l,r);
SortUtil.swap(data,l,j);

if((l-i)>THRESHOLD){
stack[++top]=i;
stack[++top]=l-1;
}
if((j-l)>THRESHOLD){
stack[++top]=l+1;
stack[++top]=j;
}

}
//new InsertSort().sort(data);
insertSort(data);
}
/**
* @param data
*/
private void insertSort(int[] data) {
int temp;
for(int i=1;i<data.length;i++){
for(int j=i;(j>0)&&(data[j]<data[j-1]);j--){
SortUtil.swap(data,j,j-1);
}
}
}

}

④ C++中sort() 是如何實現的

// 插入排序實現:
void SortInsert::insertSort(vector<int>::iterator begin, vector<int>::iterator end)
{
for (vector<int>::iterator i = begin + 1; i < end; ++i)
{
for(vector<int>::iterator j = i; *j < *(j - 1); --j )
{
std::iter_swap((j - 1), j);
}
}
}

// 冒泡排序實現:
#include <algorithm>

template<typename Iterator>
void bubbleSort(Iterator first, Iterator last)
{
Iterator i, j;
for (i = first; i != last; i++)
for (j = first; j < i; j++)
if (*i < *j)
std::iter_swap(i, j); // or std::swap(*i, *j);
}

template<typename Iterator, class StrictWeakOrdering>
void bubbleSort(Iterator first, Iterator last, StrictWeakOrdering compare)
{
Iterator i, j;
for (i = first; i != last; i++)
for (j = first; j < i; j++)
if (compare(*i, *j))
std::iter_swap(i, j);
}

// 選擇
#include <algorithm> // for: std::iter_swap, std::min_element

template <typename Iterator>
void selection_sort(Iterator begin, Iterator end)
{
Iterator min;
while (begin != end)
{
min = std::min_element(begin, end);
std::iter_swap(begin, min);
++begin;
}
}

// 快速
#include <functional>
#include <algorithm>
#include <iterator>

template< typename BidirectionalIterator, typename Compare >
void quick_sort( BidirectionalIterator first, BidirectionalIterator last, Compare cmp ) {
if( first != last ) {
BidirectionalIterator left = first;
BidirectionalIterator right = last;
BidirectionalIterator pivot = left++;

while( left != right ) {
if( cmp( *left, *pivot ) ) {
++left;
} else {
while( (left != right) && cmp( *pivot, *right ) )
--right;
std::iter_swap( left, right );
}
}

--left;
std::iter_swap( pivot, left );

quick_sort( first, left, cmp );
quick_sort( right, last, cmp );
}
}

template< typename BidirectionalIterator >
inline void quick_sort( BidirectionalIterator first, BidirectionalIterator last ) {
quick_sort( first, last,
std::less_equal< typename std::iterator_traits< BidirectionalIterator >::value_type >()
);
}

===========算啦,你還是去這里(下面是鏈接)看看吧,共同學習哦!!
http://en.wikibooks.org/w/index.php?title=Special%3ASearch&redirs=1&search=sort&fulltext=Search&ns0=1&ns4=1&ns112=1

⑤ js中sort方法的源碼,該怎麼解決

unction ArraySort(comparefn) {
// In-place QuickSort algorithm.
// For short (length <= 22) arrays, insertion sort is used for efficiency.

var custom_compare = IS_FUNCTION(comparefn);

function Compare(x,y) {
// Assume the comparefn, if any, is a consistent comparison function.
// If it isn't, we are allowed arbitrary behavior by ECMA 15.4.4.11.
if (x === y) return 0;
if (custom_compare) {
// Don't call directly to avoid exposing the builtin's global object.
return comparefn.call(null, x, y);
}
if (%_IsSmi(x) && %_IsSmi(y)) {
return %SmiLexicographicCompare(x, y);
}
x = ToString(x);
y = ToString(y);
if (x == y) return 0;
else return x < y ? -1 : 1;
};

function InsertionSort(a, from, to) {
for (var i = from + 1; i < to; i++) {
var element = a[i];
// Pre-convert the element to a string for comparison if we know
// it will happen on each compare anyway.
var key =
(custom_compare || %_IsSmi(element)) ? element : ToString(element);
// place element in a[from..i[
// binary search
var min = from;
var max = i;
// The search interval is a[min..max[
while (min < max) {
var mid = min + ((max - min) >> 1);
var order = Compare(a[mid], key);
if (order == 0) {
min = max = mid;
break;
}
if (order < 0) {
min = mid + 1;
} else {
max = mid;
}
}
// place element at position min==max.
for (var j = i; j > min; j--) {
a[j] = a[j - 1];
}
a[min] = element;
}
}

function QuickSort(a, from, to) {
// Insertion sort is faster for short arrays.
if (to - from <= 22) {
InsertionSort(a, from, to);
return;
}
var pivot_index = $floor($random() * (to - from)) + from;
var pivot = a[pivot_index];
// Pre-convert the element to a string for comparison if we know
// it will happen on each compare anyway.
var pivot_key =
(custom_compare || %_IsSmi(pivot)) ? pivot : ToString(pivot);
// Issue 95: Keep the pivot element out of the comparisons to avoid
// infinite recursion if comparefn(pivot, pivot) != 0.
a[pivot_index] = a[from];
a[from] = pivot;
var low_end = from; // Upper bound of the elements lower than pivot.
var high_start = to; // Lower bound of the elements greater than pivot.
// From low_end to i are elements equal to pivot.
// From i to high_start are elements that haven't been compared yet.
for (var i = from + 1; i < high_start; ) {
var element = a[i];
var order = Compare(element, pivot_key);
if (order < 0) {
a[i] = a[low_end];
a[low_end] = element;
i++;
low_end++;
} else if (order > 0) {
high_start--;
a[i] = a[high_start];
a[high_start] = element;
} else { // order == 0
i++;
}
}
QuickSort(a, from, low_end);
QuickSort(a, high_start, to);
}

var old_length = ToUint32(this.length);
if (old_length < 2) return this;

%RemoveArrayHoles(this);

var length = ToUint32(this.length);

// Move undefined elements to the end of the array.
for (var i = 0; i < length; ) {
if (IS_UNDEFINED(this[i])) {
length--;
this[i] = this[length];
this[length] = void 0;
} else {
i++;
}
}

QuickSort(this, 0, length);

// We only changed the length of the this object (in
// RemoveArrayHoles) if it was an array. We are not allowed to set
// the length of the this object if it is not an array because this
// might introce a new length property.
if (IS_ARRAY(this)) {
this.length = old_length;
}

return this;
}

⑥ Sort code 是什麼

sort code 意思是 (銀行)識別代碼

讀法 英 [ˈsɔːt kəʊd] 美 [ˈsɔːrt koʊd]

雙語例句:

1、For example, use a sort code and bank account number to access a customer?

例如,使用排序代碼和銀行賬戶號碼訪問客戶的簡介。

2、If the profile is not found, use the sort code to fetch defaults for this customer.

如果沒有找到,使用排序代碼取得該客戶的默認信息。

3、Messages commonly contain information about the value of a transaction, where it originated ( which store or ATM), card account number, and bank sort code.

消息通常包含有關交易金額、交易的發起位置(商店或ATM)、卡帳號和銀行代碼的信息。


(6)jssort源碼擴展閱讀:

code 意思為代碼

讀法 英 [kəʊd] 美 [kod]

n. 代碼,密碼;編碼;法典

vt. 編碼;製成法典

vi. 指定遺傳密碼

n. (Code)人名;(英、法、西)科德

短語:

source code 源代碼 ; 啟動原始碼 ; 原始碼 ; 源碼

object code 目標代碼 ; 目的碼 ; 目標碼 ; 結果碼

Code Lyoko 虛幻勇士 ; 至Net奇兵 ; 虛幻勇士專輯 ; 中文字幕版

bar code [自] 條形碼 ; 商品條碼 ; [自] 條碼 ; 條形嗎

Managed Code 託管代碼 ; 受控代碼 ; 管理代碼

country code 國家代碼 ; 國家代號 ; 國家碼

HS CODE 海關編碼 ; 商品編碼 ; 海關商品編碼 ; 稅則號

Code Complete 代碼大全 ; 代碼完成 ; 程序員必看 ; 代碼大全中文版

Code Red 紅色代碼 ; 紅色警戒 ; 代號紅色 ; 赤色代碼

⑦ 求C#里sort()函數封裝的源代碼

同意樓上說法,用reflector就可以,這是其中的一部分代碼,建議去看reflector。

1.Sort() : Void
public void Sort()
{
this.Sort(0, this.Count, null);
}
2.Sort(IComparer<T>):Void
public void Sort(IComparer<T> comparer)
{
this.Sort(0, this.Count, comparer);
}
1和2的this.Sort:
public void Sort(int index, int count, IComparer<T> comparer)
{
if ((index < 0) || (count < 0))
{
ThrowHelper.((index < 0) ? ExceptionArgument.index : ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
}
if ((this._size - index) < count)
{
ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
}
Array.Sort<T>(this._items, index, count, comparer);
this._version++;
}

3.Sort(Comparison<T>):Void
public void Sort(Comparison<T> comparison)
{
if (comparison == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
}
if (this._size > 0)
{
IComparer<T> comparer = new Array.FunctorComparer<T>(comparison);
Array.Sort<T>(this._items, 0, this._size, comparer);
}
}
最後一行的Sort:
[ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
public static void Sort<T>(T[] array, int index, int length, IComparer<T> comparer)
{
if (array == null)
{
throw new ArgumentNullException("array");
}
if ((index < 0) || (length < 0))
{
throw new ArgumentOutOfRangeException((length < 0) ? "length" : "index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
}
if ((array.Length - index) < length)
{
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
}
if ((length > 1) && (((comparer != null) && (comparer != Comparer<T>.Default)) || !TrySZSort(array, null, index, (index + length) - 1)))
{
ArraySortHelper<T>.Default.Sort(array, index, length, comparer);
}
}

⑧ 如何查看js的sort方法的源碼

sort() 方法用於對數組的元素進行排序。 語法: arrayObject.sort(sortby)描述

⑨ sort code是什麼意思

sort code的意思:n.分碼(指用於區分票據簽發行的一組號碼)。

code

  • n. 密碼,暗碼;(郵政)編碼,(電話)區號;(計算機)編碼;道德准則,行為規范;法典,法規

  • v. 把……編碼(或編號);把……譯成密碼;(給計算機)編寫指令

  • 【名】 (Code)(英、法、西)科德(人名)

  • n. (Code)人名;(英、法、西)科德

短語

ZIP CODE[郵]郵政編碼 ; 郵編 ; 美國郵區編號 ; 郵遞區號

source code源代碼 ; 源碼

postal code郵政編碼 ; 郵編 ; 郵遞區號 ; 郵政編號

詞語辨析

law, rule, regulation, code, act, constitution

這組詞都有「法同,法規」的意思,其區別是:

law普通用詞,泛指由最高當局所制訂、立法機構所通過的任何成文或不成文的法規或條例。

rule通常指機關、團體的規章、條例或比賽規則;也指對人行為、方法等所作的規定,還可指習俗所承認的規定。

regulation普通用詞,指用於管理、指導或控制某系統或組織的規則、規定或原則等。

code指某一階層或社會所遵守的一整套法典、法規或法則;也可指與某一特殊活動或主題有關的規則。

act指經立法機構通過並由行政管理簽署的法案。

constitution指治理國家或國家在處理內外政務時所遵循的基本法律和原則;也指規章規則的匯集。

熱點內容
演算法題寫錯了 發布:2024-05-05 13:34:57 瀏覽:804
sql按小時分組 發布:2024-05-05 13:26:25 瀏覽:94
張藝謀我們一家訪問人 發布:2024-05-05 12:38:05 瀏覽:111
美版安卓系統怎麼安裝 發布:2024-05-05 12:37:18 瀏覽:920
qq郵箱緩存地址 發布:2024-05-05 12:37:16 瀏覽:986
電位演算法 發布:2024-05-05 12:36:01 瀏覽:727
我的世界清風斗羅大陸伺服器地址 發布:2024-05-05 12:35:50 瀏覽:453
dell伺服器如何進入bios 發布:2024-05-05 12:34:26 瀏覽:330
在線名片製作源碼 發布:2024-05-05 12:29:27 瀏覽:447
陰陽師按鍵腳本 發布:2024-05-05 12:00:33 瀏覽:760