我利用业余时间来编写一个小排序机制:一个冒泡排序机制,这就是我想出的:
public class BubbleSort
{
private bool _numbersAreSorted = false;
public float[] Sort(float[] _list)
{
float num1;
float num2;
while (!_numbersAreSorted)
{
_numbersAreSorted = true;
for (int i = 0; i < _list.Length - 1; i++)
{
num1 = _list[i];
num2 = _list[i + 1];
if (num1 > num2)
{
_list[i] = num2;
_list[i + 1] = num1;
i--;
_numbersAreSorted = false;
}
}
}
return _list;
}
}
正如你所看到的,这不是什么花哨的东西,但它完成了工作。我的问题是:这是一种编程泡泡分拣机制的“有效”方式,还是可以进行一些改进?
答案 0 :(得分:0)
试试这个:
import Docker from 'dockerode'
var docker = new Docker({host: 'http://127.0.0.1', port: 52376});
export default {
getContainerById: {
type: Container,
args: {
id: {type: new GraphQLNonNull(GraphQLID)}
},
async resolve(source, {id}, {rootValue}) {
isLoggedIn(rootValue);
const container = await r.table('containers').get(id);
if (!container) {
throw errorObj({_error: 'Container not found'});
}
return container;
}
},
fetchContainers: {
type: new GraphQLList(Container),
async resolve(source, {id}, {rootValue}) {
isLoggedIn(rootValue);
docker.listContainers(function(err, containers) {
});
if (!containers) {
throw errorObj({_error: 'Container not found'});
}
return containers
}
}
};
一些评论: