由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 请大虾验证!
相关主题
Sort a stack without using auxiliary stacks or arrays[合集] 一道微软面试题
嵌入式系统用什么sorting算法比较好?[合集] 两个经典面题
一道热门的 Google 面试题 (转载)看看这个题吧brainbench上的c
一FG家常见题 (转载)今天面了个老印
If using C++, please avoid the use of STL for these questio (转载)一道MS面试题 (转载)
merge two Binary search tree in O(n) time and O(1) space有谁看过youtube上的算法课吗?
stack/heap corruption请教windows 7 怎么增加堆栈上限
array allocation in c为什么会有recursion stack overflow这个问题?
相关话题的讨论汇总
话题: e1话题: sort话题: e2话题: isfull话题: isempty
进入Programming版参与讨论
1 (共1页)
l*****l
发帖数: 171
1
俺在 JOBHUNTING 做的一道题, 不知是否正确, 请大虾验证!
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.
How about this?
l*****l
发帖数: 171
2
俺优化以下:
void sort(stack &s, int numSorted)
{
element *e1;
element *e2;
if (s.size() <= 1+numSorted) {
return;
}
e1 = s.pop();
if(e1 < s.top()) {
e2 = s.pop();
s.push(e1);
sort(s);
s.push(e2);
} else {
sort(s);
s.push(e1);
}
}

【在 l*****l 的大作中提到】
: 俺在 JOBHUNTING 做的一道题, 不知是否正确, 请大虾验证!
: 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.
: How about this?

q*c
发帖数: 9453
3
这个是 meaningless...用的内存比全部新开 array 多,
效率低下, 不知道这题目为啥。而且 sort(stack)
函数也没定义, 不知道咋运行。
这个题目一定要多余的内存,否则罪底下那个元素无法出来。

【在 l*****l 的大作中提到】
: 俺优化以下:
: void sort(stack &s, int numSorted)
: {
: element *e1;
: element *e2;
: if (s.size() <= 1+numSorted) {
: return;
: }
: e1 = s.pop();
: if(e1 < s.top()) {

c*****t
发帖数: 1879
4
the only minor problem i see is that size () is not provided.

【在 l*****l 的大作中提到】
: 俺在 JOBHUNTING 做的一道题, 不知是否正确, 请大虾验证!
: 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.
: How about this?

l*****l
发帖数: 171
5
I think I can use isEmpty()/isFull():)

【在 c*****t 的大作中提到】
: the only minor problem i see is that size () is not provided.
P*****f
发帖数: 2272
6
多余内存在递归的程序stack上
所以这个题有点好玩:不能用辅助栈,但是可以用程序调用的栈
嘿嘿

这个是 meaningless...用的内存比全部新开 array 多,
效率低下, 不知道这题目为啥。而且 sort(stack)
函数也没定义, 不知道咋运行。
这个题目一定要多余的内存,否则罪底下那个元素无法出来。

【在 q*c 的大作中提到】
: 这个是 meaningless...用的内存比全部新开 array 多,
: 效率低下, 不知道这题目为啥。而且 sort(stack)
: 函数也没定义, 不知道咋运行。
: 这个题目一定要多余的内存,否则罪底下那个元素无法出来。

l*****l
发帖数: 171
7
这个也就是面世题, 没有实际意义. 如果有N个数, 要做N层RECURSION.
N必须很小才行.

【在 P*****f 的大作中提到】
: 多余内存在递归的程序stack上
: 所以这个题有点好玩:不能用辅助栈,但是可以用程序调用的栈
: 嘿嘿
:
: 这个是 meaningless...用的内存比全部新开 array 多,
: 效率低下, 不知道这题目为啥。而且 sort(stack)
: 函数也没定义, 不知道咋运行。
: 这个题目一定要多余的内存,否则罪底下那个元素无法出来。

s*******d
发帖数: 59
8
让人想起武林外传里的六扇门测试题。
1 (共1页)
进入Programming版参与讨论
相关主题
为什么会有recursion stack overflow这个问题?If using C++, please avoid the use of STL for these questio (转载)
我写的quick sortmerge two Binary search tree in O(n) time and O(1) space
一个java class downcast 的问题stack/heap corruption
关于在rotated sorted array中查找的问题array allocation in c
Sort a stack without using auxiliary stacks or arrays[合集] 一道微软面试题
嵌入式系统用什么sorting算法比较好?[合集] 两个经典面题
一道热门的 Google 面试题 (转载)看看这个题吧brainbench上的c
一FG家常见题 (转载)今天面了个老印
相关话题的讨论汇总
话题: e1话题: sort话题: e2话题: isfull话题: isempty