boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 一道Microsoft的面试题
相关主题
What does the default constructor do?
不明白C++的一个地方
[合集] C++的弱问题
Initialization list的一个问题
问行C++代码
c++类未完成初始化,如何引用this?
又一道面试题,我是不是想多了?
求C/C++面试题
一个C++面试题分析
腆着脸在问一道
相关话题的讨论汇总
话题: ball话题: array话题: color话题: ballcolor话题: class
进入Programming版参与讨论
1 (共1页)
b*********n
发帖数: 1258
1
C++ Prototype
==============================
class Ball
{
public:
enum BallColor { RED, BLUE };
BallColor Color() const { return _color; }
private:
BallColor _color;
// Other data in class (unrelated to assignment)
};
我想在主函数里面定义一个Ball array,每一个元素都是一个Ball type
如果我不修改Ball class,可以初始化那个Ball array吗?
我的想法是修改Ball class的ctor
或者定义一个method来初始化Ball array里面的每一个元素
但是不知道,如果不修改这个class,可不可以实现同样的目的
谢谢
r****5
发帖数: 11
2
把原题贴上来吧

【在 b*********n 的大作中提到】
: C++ Prototype
: ==============================
: class Ball
: {
: public:
: enum BallColor { RED, BLUE };
: BallColor Color() const { return _color; }
: private:
: BallColor _color;
: // Other data in class (unrelated to assignment)

b*********n
发帖数: 1258
3
What's your opinion to my previous question? Thanks.
=============================
Given an array of balls, which can be one of two colors (RED or BLUE), w
rite a function that partitions the array in-place such that on exit fro
m the function all the balls of the same color are contiguous. It does n
ot matter whether the red or blue balls come first. The return value fro
m the function is the index of the first ball of the second color. If t
here is only one color of balls in the array then th

【在 r****5 的大作中提到】
: 把原题贴上来吧
r****5
发帖数: 11
4
in-place sorting,这个好像有经典解法

【在 b*********n 的大作中提到】
: What's your opinion to my previous question? Thanks.
: =============================
: Given an array of balls, which can be one of two colors (RED or BLUE), w
: rite a function that partitions the array in-place such that on exit fro
: m the function all the balls of the same color are contiguous. It does n
: ot matter whether the red or blue balls come first. The return value fro
: m the function is the index of the first ball of the second color. If t
: here is only one color of balls in the array then th

b*********n
发帖数: 1258
5
这个inplace sorting我知道
我想问的是那个class Ball如何初始化
谢谢

【在 r****5 的大作中提到】
: in-place sorting,这个好像有经典解法
r****5
发帖数: 11
6
不用初始化吧,Partition函数的输入,应该可以直接用

【在 b*********n 的大作中提到】
: 这个inplace sorting我知道
: 我想问的是那个class Ball如何初始化
: 谢谢

S*********g
发帖数: 5298
7
The question starts with "given an array"
It is given, you don't need to worry about that.
What you need to do is to partite the array

【在 b*********n 的大作中提到】
: 这个inplace sorting我知道
: 我想问的是那个class Ball如何初始化
: 谢谢

i*****f
发帖数: 578
8
heap sorting could work?

【在 r****5 的大作中提到】
: in-place sorting,这个好像有经典解法
p***o
发帖数: 1252
9
哪有那么复杂,参见std::partition。

【在 i*****f 的大作中提到】
: heap sorting could work?
e***s
发帖数: 2
10
参考快速排序的partition部分就是了。。。
1 (共1页)
进入Programming版参与讨论
相关主题
腆着脸在问一道
c++ 语法
请教大家一道C的面试题
vector在constructor里初始化
prototype和abstract factory的区别
c# question: char_array.ToString() is not working ?
C++ 中 myobject * a =new myobject[n] 的问题
question about const reference
C++ question
What are possible reasons for the program to crash before r
相关话题的讨论汇总
话题: ball话题: array话题: color话题: ballcolor话题: class