由买买提看人间百态

topics

全部话题 - 话题: sorting
首页 上页 1 2 3 4 5 6 7 8 9 10 (共10页)
s****u
发帖数: 118
1
来自主题: Programming版 - 几道面试题:memory, sort, 等
所以我就是说可以啊,没事谁那样写啊,一个sort就完了 -_-
q********c
发帖数: 1774
2
来自主题: Programming版 - 几道面试题:memory, sort, 等

Bucket sort, for sure. he he
a****l
发帖数: 8211
3
来自主题: Programming版 - 几道面试题:memory, sort, 等
right, what if the numbers are floats? still use radix sort? so there is
some "uniqueness" of the data, right?
s****u
发帖数: 118
4
来自主题: Programming版 - 几道面试题:memory, sort, 等
终于找到了,introduction to algorithm 9.3,虽然bt了点,但是nth_element还是可
以O(n)
所以quicksort就可以O(nlogn),也不知道前面讲sorting的就咬定worst是n方
y****e
发帖数: 23939
5
来自主题: Programming版 - 几道面试题:memory, sort, 等
1 用 counting sort 吧
P********e
发帖数: 2610
6
来自主题: Programming版 - 几道面试题:memory, sort, 等
其实本质上就是radix sort, by least significant bit
0 1 2 3 4 5 6 7 8 9
same as ten bucket
j*****k
发帖数: 1198
7
来自主题: Programming版 - 问一个sort的问题
想用stl sort来按string size排序。在relational function cmp里面
如果这样用就没问题
bool cmp(string &s1, string &s2)
{
return s1<=s2;
}
可是如果以下面的方式用,就会出现segment fault, 什么原因呢?
bool cmp(string &s1, string &s2)
{
return (s1.length()) <= (s2.length());
}
谢谢
b**a
发帖数: 1118
8
Design an efficient algorithm to sort elements in a stack in either
ascending/descending order, using only pop(), top(), push(), isEmpty(),
isFull(). Do not use any auxiliary stacks or arrays.
I found this question in jobhunting board. the anwser given by a niu ren is
Is this right? Does not look like right one.Thanks.
S*******t
发帖数: 97
9
来自主题: Programming版 - 问一下bitmap sorting的问题
看了programming pearls里面的bitmap sorting,
大致上的idea是明白了,但是看了书后面的源码,
实在不明白那三个function set, clr test实现
的原理。有没有人可以解释一下?
#define BITSPERWORD 32
#define SHIFT 5
#define MASK 0x1F
#define N 10000000
int a[1 + N/BITSPERWORD];
void set(int i) { a[i>>SHIFT] |= (1<<(i & MASK)); }
void clr(int i) { a[i>>SHIFT] &= ~(1<<(i & MASK)); }
int test(int i){ return a[i>>SHIFT] & (1<<(i & MASK)); }
d*****u
发帖数: 17243
10
来自主题: Programming版 - sort algorithm
如果不计memory成本的话,是可以有O(n)的time complexity的
比如bucket sort
g*****g
发帖数: 34805
11
来自主题: Programming版 - sort algorithm
Only counting sort is O(n), if you know the range.
r*******n
发帖数: 3020
12
来自主题: Programming版 - sort algorithm
The sort algorithms based on comparison are limited by nlogn
k****f
发帖数: 3794
13
来自主题: Programming版 - Sort cygwin question
我一般是用tr把tab转成单空格
然后再用sort
c*****t
发帖数: 1879
14
来自主题: Programming版 - 如何 randomize 一个sorted的文件 ?
sort by 2nd or 3rd character :)
a********r
发帖数: 58
15
来自主题: Programming版 - underlying sort algorithm for SET in STL?
What's the underlying sort algorithm for SET in C++ STL? Thanks!
t****t
发帖数: 6806
16
来自主题: Programming版 - underlying sort algorithm for SET in STL?
usually sort() is based on quicksort. however it's implementation defined,
given the complexity requirement is satisfied.
t****t
发帖数: 6806
17
来自主题: Programming版 - underlying sort algorithm for SET in STL?
someone already told you it's red-black tree. it's always sorted.

thanks
x*******u
发帖数: 2074
18
来自主题: Programming版 - underlying sort algorithm for SET in STL?
没有set::sort()这个函数的
插入/删除等modifier操作都必须保证整个tree是binary search tree

thanks
h*******u
发帖数: 15326
19
来自主题: Programming版 - underlying sort algorithm for SET in STL?
set里面值修改后不能自动sort,怎么回事。
如果是插入或删除则能保证自动排序
e******d
发帖数: 310
20
来自主题: Programming版 - 请教如何使用qsort() to sort string.
I want to sort strings using qsort(), and try the following code, but doesn
't work. Could you please help me out. Thank you.
=============================================
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
int mystrcmp(const void * str1, const void * str2)
{
return strcmp( (const char*)str1, (const char*)str2 ) ;
}
int main()
{
int n = 4;
char *pstr[] = {"God", "Bed", "Act", "Cup"};
qsort(pstr, n, sizeof(char*), mystrcmp);
int i = 0;
for(i = 0;
p***o
发帖数: 1252
21
来自主题: Programming版 - 请教如何使用qsort() to sort string.
It really doesn't matter which language you are using.
Actually qsort is a good example to show someone familiar with C
the idea of functor in C++. While C++ automatically matches
(or finds a mismatch of) the types for std::sort, in C you have
to do it by hand and be very careful; otherwise you will get
the same error as LZ.
X****r
发帖数: 3557
22
来自主题: Programming版 - 请教如何使用qsort() to sort string.
qsort passes pointers to the objects being compared. Your objects
in the array are "char *", thus the comparison function parameters
have actual type "char **".
For example, if you're sorting integers, you would do:
int myintcmp(const void *p1, const void *p2) {
return *(const int*)p1 - *(const int *)p2;
}
int data[] = {1,3,2,4};
qsort(data, sizeof(data)/sizeof(data[0]), sizeof(data[0]), myintcmp);
Just replace "int" in above example with "char *" you'll see.

const*)str2);
c**********e
发帖数: 2007
23
来自主题: Programming版 - C++ Q10: list and sort
#include
#include
#include
#include
using namespace std;
struct A {
int number;
A(int n=0):number(n) {}
bool operator<(const A& a) const { return number };
A generator() {
static A current(10);
current.number--;
return current;
}
int main()
{
std::list l;
std::generate_n(std::back_inserter(l), 10, generator);
std::sort(l.begin(),l.end());
return 0;
}
Referring to the code above, which one of the following is true regardin
d*****d
发帖数: 46
24
来自主题: Programming版 - C++ Q10: list and sort
c
sort need RandomAccessIterator.
N***m
发帖数: 4460
25
how about sorting the corresponding map?
r****o
发帖数: 1950
26
quicksort通用的算法需要recursion,不太适合用于embedded system,因为有可能stack
overflow.
那大家都用的哪种sorting呢?
g*****g
发帖数: 34805
27
quicksort can be in place, I dont' think that can cause overflow.
Merge sort may also be popular since it has worst case O(nlogn) and it's
stable.

stack
r****o
发帖数: 1950
28
loop-based quicksort也需要一个stack,不过我不是很确定会不会导致stack
overflow.
Merge sort需要额外空间,不太好吧。
w***g
发帖数: 5958
29
如果想避免递归的话可以用heap sort。性能应该和quicksort差不多。

stack
P********e
发帖数: 2610
30
我个人观察,很多直接用selection sort

stack
a****l
发帖数: 8211
31
你应该先问应该不应该用sort.

stack
X****r
发帖数: 3557
32
来自主题: Programming版 - 我也来一个, quick sort 只要一行。
There is really no point writing Python code like that.
If you like functional style, just use Haskell:
q s = case s of{[]->[];(x:xs)->q [y|y<-xs,y=x]}
Which does almost (except for the case the the pivot element is repeated)
exactly you do here and is more readable.
Note that this 'quicksort' (both the Python and the Haskell version)
is not really a quicksort, i.e. it does not sort in-place, thus has
quadratic space and time cost.
t*s
发帖数: 1504
33
来自主题: Programming版 - 我也来一个, quick sort 只要一行。
this is not pythonic
the pythonic way is to use built-in sort
p*********t
发帖数: 2690
34
来自主题: Programming版 - 什么时候该用什么sort算法
用forward_list的sort算法,这个比你说的2个都快。
M7
发帖数: 219
35
来自主题: Programming版 - Please help: sort XML with Linq
有三个ListItem, 每个ListItem都有一个Property bag (dictionary of key-value
pair)。Property bag里面基本都是无关的key-value pair。有一个key是"SortByKey",
我希望根据SortByKey的value来sort这三个ListItem. 请问用Linq怎么做?
谢谢。

283650e7728e47d1b003b78dc85e8105


iHoVHJ

http://www.w3.org/2001/XMLSchema" i:type="d9p1:strin... 阅读全帖
r*****t
发帖数: 4793
36
【 以下文字转载自 Linux 讨论区 】
发信人: ravecat (八三年的赵英俊), 信区: Linux
标 题: 请问如何用sort命令给数据排序?
发信站: BBS 未名空间站 (Thu Oct 3 02:24:32 2013, 美东)
我有两个文件F1和F2,F1和F2的column 1 是同类字符但是顺序不同
我想把文件F2里的各行,按照文件F1 的column 1 排序,应该如何做?
m*******l
发帖数: 12782
37
awk 'BEGIN {j = 0} { if (content[$1] != "" ) { content2[j $1] = $0 ; j++ ; }
else { content[$1] = $0 ; } } END { for ( i in content2 ) print i,
content2[i] ; } ' F1.dat F2.dat | sort | awk '{ $1="" ; print ; }'
w**z
发帖数: 8232
38
quick sort 很容易写吗?这种算法,只要知道意思,就行了。真当场写出来又如何?

太大
w**z
发帖数: 8232
39
quick sort 很容易写吗?这种算法,只要知道意思,就行了。真当场写出来又如何?

太大
k*******n
发帖数: 190
40
DEV 是什么意思? SR DEV 是什么?
比 quick sort 还难吗?
不写难道就不能找工作了?
W***o
发帖数: 6519
41
记得最一开始设计过一个图灵机来sort 这种pattern的string
e****t
发帖数: 17914
42
你这多了个argument吧
一般sorted和lamda 一起用
s*****V
发帖数: 21731
43
sort 最快就是O(nlogn),只找最大值O(n)就可以。
n****l
发帖数: 1739
44
不能比这个代码更简练了, 3百万都不会“慢”。 找找其他的问题。 另外这个max应
该没有sort。
f*******l
发帖数: 8811
45
如果用 acronym package的话,而不是用 glossary, 如何自动sort呢。
T*******n
发帖数: 493
46
You would have to write a MakeIndex style file to sort and format the
list of acronyms. Unless you have so many of these, it's not worth the
effort.
f*******h
发帖数: 1269
47
来自主题: Unix版 - How to sort email address?
I have hundreds of email addresses, like
a*[email protected]
d*[email protected]
...
How to sort by domain names? THanks ahead!
b****e
发帖数: 985
48
来自主题: Unix版 - How to sort email address?
sort -t@ +1
t**********o
发帖数: 124
49
来自主题: Unix版 - How to sort files by date?
Is it possible to use some options of 'sort'?
tutu
b***l
发帖数: 15
50
来自主题: Unix版 - How to do that using "sort" command?
But if I want to sort the followig first according column 1 and then column 3
and the column 2, how to do it? I want a general solution for any order of the
columns.
1 2 3
1 2 4
1 3 3
1 4 3
The expected result is:
1 2 3
1 3 3
1 4 3
1 2 4

then
首页 上页 1 2 3 4 5 6 7 8 9 10 (共10页)