?? sortdemo.c
字號:
/* Bai tap 1_90 - Minh hoa phuong phap sap xep doi cho truc tiep */
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <dos.h>
#define MAX 10 // so luong phan tu toi da (khong duoc qua 10)
#define DONG 10 // dong bat dau in mang
#define DELAY 300
int mang[MAX]; // Bien toan cuc
int cot = (80 - 5 * MAX) / 2;
void hoandoi(int i, int j)
{
int xi = cot + 2 + i * 5;
int xj = cot + 2 + j * 5;
int xdest = xj;
int yi = DONG + 1;
int yj = DONG + 1;
int k, l;
textcolor(YELLOW);
for (k = 0; k<2; k++)
{
gotoxy(xi,yi--);
cprintf(" ");
gotoxy(xj,yj++);
cprintf(" ");
gotoxy(xi,yi);
cprintf("%2d",mang[i]);
gotoxy(xj,yj);
cprintf("%2d",mang[j]);
delay(DELAY);
}
while (xi<xdest)
{
gotoxy(xi++,yi);
cprintf(" ");
gotoxy(xj--,yj);
cprintf(" ");
gotoxy(xi,yi);
cprintf("%2d",mang[i]);
gotoxy(xj,yj);
cprintf("%2d",mang[j]);
delay(DELAY);
}
for (k = 0; k<2; k++)
{
gotoxy(xi,yi++);
cprintf(" ");
gotoxy(xj,yj--);
cprintf(" ");
gotoxy(xi,yi);
cprintf("%2d",mang[i]);
gotoxy(xj,yj);
cprintf("%2d",mang[j]);
delay(DELAY);
}
xdest = mang[i];
mang[i] = mang[j];
mang[j] = xdest;
}
void in_bien_i(int i)
{
gotoxy(cot+(i-1)*5+1,DONG-3);
textcolor(BLACK);
cprintf("%c",25);
gotoxy(cot+(i)*5+1,DONG-3);
textcolor(WHITE + BLINK);
cprintf("%c",25);
delay(DELAY);
}
void in_bien_j(int j)
{
gotoxy(cot+(j-1)*5+1,DONG+5);
textcolor(BLACK);
cprintf("%c",24);
gotoxy(cot+(j)*5+1,DONG+5);
textcolor(WHITE + BLINK);
cprintf("%c",24);
delay(DELAY);
}
void main()
{
// Phan khai bao bien
char tieude[]="CHUONG TRINH DEMO MOT PHUONG PHAP SAP XEP (SORT)";
char khungtrai[3] = {'
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -