带标题......
的main.c
public class LevelScreen extends Stage implements Screen {
private Batch batch;
private Camera camera;
private Texture ballTexture;
private Sprite ball;
private Viewport viewport;
//com
private Vector3 point = new Vector3();
private World world;
private Box2DDebugRenderer box2DDebugRenderer;
private CircleShape circleShape;
private FixtureDef fixtureDef;
private BodyDef bodyDef;
private Body circleBody;
private static final float SCENE_WIDTH = 1080;
private static final float SCENE_HEIGHT = 1920f;
public LevelScreen() {
super(new FitViewport(SCENE_WIDTH, SCENE_HEIGHT, new OrthographicCamera(SCENE_WIDTH, SCENE_HEIGHT)));
batch = getBatch();
camera = getCamera();
viewport = getViewport();
world = new World(new Vector2(0,-9.8f), true);
box2DDebugRenderer = new Box2DDebugRenderer();
bodyDef = new BodyDef();
bodyDef.type = BodyDef.BodyType.DynamicBody;
bodyDef.position.set(600, 1000);
ballTexture = new Texture("ball.png");
ball = new Sprite(ballTexture);
ball.setPosition(0,0);
circleShape = new CircleShape();
circleShape.setRadius(25f);
fixtureDef = new FixtureDef();
fixtureDef.shape = circleShape;
fixtureDef.density = 0.5f;
fixtureDef.friction = 0.4f;
fixtureDef.restitution = 0.6f;
circleBody = world.createBody(bodyDef);
circleBody.createFixture(fixtureDef);
box2DDebugRenderer = new Box2DDebugRenderer(
true, /* draw bodies */
false, /* don't draw joints */
true, /* draw aabbs */
true, /* draw inactive bodies */
false, /* don't draw velocities */
true /* draw contacts */);
Gdx.input.setInputProcessor(this);
}
@Override
public void show() {
System.out.println("show");
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(camera.combined);
batch.begin();
ball.draw(batch);
batch.end();
world.step(1 / 60f, 6, 2);
ball.setPosition(circleBody.getPosition().x - 25f, circleBody.getPosition().y - 25f);
box2DDebugRenderer.render(world, viewport.getCamera().combined);
}
@Override
public void resize(int width, int height) {
viewport.update(width, height);
System.out.println("resize");
}
@Override
public void pause() {
System.out.println("pause");
}
@Override
public void resume() {
System.out.println("resume");
}
@Override
public void hide() {
System.out.println("hide");
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
viewport.getCamera().unproject(point.set(screenX, screenY, 0));
return false;
}
}
sema.c
int main()
{
double *a = NULL ,n;
read(&a,&n);
clock_t start,stop;
start = clock();
bubblesort(a,n);
stop = clock();
float elapsedTime = (stop - start)/CLOCKS_PER_SEC;
printf("%f",elapsedTime);
write(a,n);
free(a);
return 0;
}
sema.h
void read(int *a,int n)
{
int i;
scanf("%d",&n);
a = (int*)malloc(n*sizeof(int));
if(a == 0){printf("Error");return 0;}
for(i = 0; i < n; ++i){
a[i] = rand() % 100;
}
}
void bubblesort(int *a,int n)
{
int i,j,csere;
for(i = 0; i < n-1; ++i){
for(j = 0; j < n - i -1; ++j){
if (a[j] > a[j + 1]){
csere = a[j];
a[j] = a[j + 1];
a[j + 1] = csere;
}
}
}
}
void write(int *a,int n)
{
int i;
for(i = 0; i < n; ++i){
printf("%i ",a[i]);
}
}
我用调试器来查找我的任何问题。我的写功能不起作用,因为它认为n为0,但我输入了。而且测量时间不起作用我得到零。我真的不明白为什么如果我输入,则n为零。
答案 0 :(得分:-1)
在main中,您将变量初始化为double,但在其他函数中,将其作为整数。
在read()中,
原型是void read (int *a, int *n);
但你定义了void read(int *a, int a)
和read(),为什么你在“if condition”中返回0,因为你提到了void type。