c语言的代码简化

void quicksort(int r[1001],int s,int e)
{
   int t = r[s];//哨兵,为开头的那个
   int f = s+1;
   int b = e;//f为前向指针,从s+1开始,b为反向指针,从e开始
   int m = 0;
   if(s>=e)return;//退出条件
   
   while(f<=b)
   {
       while(f<=b&&r[f]<=t) f++;//在前面找比哨兵大的元素
       while(f<=b&&r[b]>=t) b--;//在后面找比哨兵小的元素
       //交换这两个元素
       if(f<b){
            m = r[f];
            r[f] = r[b];
            r[b] = m;
            f++;    b--;
       }

   }

  http://v.17173.com/playlist_13938489.html

  http://v.17173.com/playlist_13939680.html

  http://v.17173.com/playlist_13940838.html

  http://v.17173.com/playlist_13942305.html

  http://v.17173.com/playlist_13943443.html

  http://v.17173.com/playlist_13944295.html

  http://v.17173.com/playlist_13945435.html

  http://v.17173.com/playlist_13946131.html

  http://v.17173.com/playlist_13947669.html

  http://v.17173.com/playlist_13948598.html

  http://v.17173.com/playlist_13949386.html

  http://v.17173.com/playlist_13950253.html

  http://v.17173.com/playlist_13951065.html

  http://v.17173.com/playlist_13951841.html

  http://v.17173.com/playlist_13952703.html

  http://v.17173.com/playlist_13953491.html

  http://v.17173.com/playlist_13954243.html

  http://v.17173.com/playlist_13954975.html

  http://v.17173.com/playlist_13955837.html

  http://v.17173.com/playlist_13956703.html

  http://v.17173.com/playlist_13957462.html

  http://v.17173.com/playlist_13958117.html

  http://v.17173.com/playlist_13959267.html

  http://v.17173.com/playlist_13959901.html

  http://v.17173.com/playlist_13960660.html

  http://v.17173.com/playlist_13961401.html

  http://v.17173.com/playlist_13962080.html

  http://v.17173.com/playlist_13962726.html

  http://v.17173.com/playlist_13963334.html

  http://v.17173.com/playlist_13964063.html

  http://v.17173.com/u/112491257/playlist/

  http://v.17173.com/playlist_13965404.html

  http://v.17173.com/playlist_13965998.html

  http://v.17173.com/playlist_13966839.html

  http://v.17173.com/playlist_13967762.html

  http://v.17173.com/playlist_13968527.html

  http://v.17173.com/playlist_14014375.html

  http://v.17173.com/playlist_14014999.html

  http://v.17173.com/playlist_14015817.html

  http://v.17173.com/playlist_14016522.html

  http://v.17173.com/playlist_14017479.html

  http://v.17173.com/playlist_14018216.html

  http://v.17173.com/playlist_14020977.html

  http://v.17173.com/playlist_14013332.html

  http://bbs.taobao.com/catalog/thread/154521-266598260.htm

  http://bbs.taobao.com/catalog/thread/154521-266599664.htm

  http://bbs.taobao.com/catalog/thread/154521-266592400.htm

  http://bbs.taobao.com/catalog/thread/154521-266598673.htm

  http://bbs.taobao.com/catalog/thread/154521-266597284.htm

  http://blog.1688.com/article/i36511560.html

  http://blog.1688.com/article/i36511614.html

  http://blog.1688.com/article/i36511688.html

  http://blog.1688.com/article/i36511754.html

  http://blog.1688.com/article/i36511914.html

  http://blog.1688.com/article/i36512490.html

  http://blog.1688.com/article/i36512550.html

  http://blog.1688.com/article/i36512630.html

  http://blog.1688.com/article/i36512061.html

   //交换哨兵和r[b],r[b]肯定要比哨兵小
   r[s] = r[b];
   r[b] = t;
   //排两边的
   quicksort(r,s,b-1);
   quicksort(r,b+1,e);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
贪吃蛇是一个经典的小游戏,其实现需要使用图形界面或者游戏引擎。如果您希望了解C语言实现的简化版贪吃蛇,可以参考下面的代码: ``` #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <windows.h> #define WIDTH 20 // 地图宽度 #define HEIGHT 20 // 地图高度 #define MAX_LENGTH (WIDTH * HEIGHT) // 蛇的最大长度 int snakeX[MAX_LENGTH]; // 蛇的x坐标 int snakeY[MAX_LENGTH]; // 蛇的y坐标 int length = 3; // 蛇的初始长度 int foodX, foodY; // 食物的坐标 int score = 0; // 得分 int direction; // 蛇头的方向:1为上,2为下,3为左,4为右 int speed = 200; // 蛇的速度 void initMap(); // 初始化地图 void initSnake(); // 初始化蛇 void generateFood(); // 生成食物 void move(); // 移动蛇 void updateDirection(); // 更新方向 void gameOver(); // 游戏结束 int main() { initMap(); initSnake(); generateFood(); while (1) { move(); Sleep(speed); } return 0; } void initMap() { system("cls"); for (int i = 0; i < WIDTH + 2; i++) { printf("#"); } printf("\n"); for (int i = 0; i < HEIGHT; i++) { printf("#"); for (int j = 0; j < WIDTH; j++) { printf(" "); } printf("#\n"); } for (int i = 0; i < WIDTH + 2; i++) { printf("#"); } printf("\n"); printf("Score: %d\n", score); } void initSnake() { snakeX = WIDTH / 2; snakeY = HEIGHT / 2; snakeX = snakeX; snakeY = snakeY + 1; snakeX = snakeX; snakeY = snakeY + 1; for (int i = 0; i < length; i++) { printf("@"); gotoxy(snakeX[i] + 1, snakeY[i] + 1); } } void generateFood() { srand((unsigned)time(NULL)); do { foodX = rand() % WIDTH; foodY = rand() % HEIGHT; } while (foodX == snakeX && foodY == snakeY); gotoxy(foodX + 1, foodY + 1); printf("*"); } void move() { if (_kbhit()) { updateDirection(); } int tailX = snakeX[length - 1]; int tailY = snakeY[length - 1]; gotoxy(tailX + 1, tailY + 1); printf(" "); for (int i = length - 1; i > 0; i--) { snakeX[i] = snakeX[i - 1]; snakeY[i] = snakeY[i - 1]; } switch (direction) { case 1: snakeY--; break; case 2: snakeY++; break; case 3: snakeX--; break; case 4: snakeX++; break; } if (snakeX == foodX && snakeY == foodY) { score++; length++; generateFood(); if (speed > 50) { speed -= 10; } } if (snakeX < 0 || snakeX >= WIDTH || snakeY < 0 || snakeY >= HEIGHT) { gameOver(); return; } for (int i = 1; i < length; i++) { if (snakeX[i] == snakeX && snakeY[i] == snakeY) { gameOver(); return; } } gotoxy(snakeX[0] + 1, snakeY + 1); printf("@"); gotoxy(WIDTH + 4, 2); printf("Score: %d", score); } void updateDirection() { char ch = _getch(); switch (ch) { case 'w': if (direction != 2) { direction = 1; } break; case 's': if (direction != 1) { direction = 2; } break; case 'a': if (direction != 4) { direction = 3; } break; case 'd': if (direction != 3) { direction = 4; } break; } } void gameOver() { system("cls"); printf("Game Over!\n"); printf("Score: %d\n", score); system("pause"); exit(0); } ``` 以上是简化版贪吃蛇的C语言代码。在这个代码中,我们使用了Windows API中的`gotoxy()`函数,来实现在控制台上输出蛇和食物。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值