Thứ Sáu, 25 tháng 12, 2015

Chương trình mô phỏng bài toán Tháp Hà Nội sử dụng đệ quy.



Lưu ý: Code này chỉ chạy được trên Borland C !

#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>

#define move(x,y,z) makeblocks(x,y,z); delay(t); delblocks(x, y, z);

int t;
int a[] = { 0, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25 };
int color[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
int bg = 0;


void makeblocks(int x, int y, int z)
{
    int h = a[z] / 2;
    window(x - h, y, x + h, y);
    textbackground(color[z]);
    textcolor(color[z]);
    clrscr();
}

void delblocks(int x, int y, int z)
{
    int h = a[z] / 2;
    window(x - h, y, x + h, y);
    textbackground(bg);
    clrscr();
}

void tower(int x, int y, int m)
{
    for (int i = m; i >= 1; i--)
        makeblocks(x, y - m + i, i);
}

void moveblocks(int x1, int y1, int x2, int y2, int z)
{
    static int count = 0;
    int x, y;
    count++;
    window(1, 1, 24, 1);
    textbackground(BLUE);
    clrscr();
    textcolor(WHITE);
    cprintf("\nLan dich chuyen thu: ");
    textcolor(YELLOW + BLINK);
           cprintf("%4d", count);
    for (y = y1; y >= 4; y--)
    {
        move(x1, y, z);
        }
    if (x1<x2)
    for (x = x1; x <= x2; x++)
    {
        move(x, 4, z);
    }
    else
    for (x = x1; x >= x2; x--)
    {
        move(x, 4, z );
    }
    for (y = 4; y <= y2; y++)
    {
        move(x2, y, z);
    }
    makeblocks(x2, y2,z);
}

void movetower(int x1, int y1, int x2, int y2, int x3, int y3, int m)
{
    if (m < 1)    return;
    else
    if (m == 1)
        moveblocks(x1, y1, x2, y2, 1);
    else
    {
        movetower(x1, y1 - 1, x3, y3, x2, y2, m - 1);
        moveblocks(x1, y1, x2, y2, m);
        movetower(x3, y3, x2, y2 - 1, x1, y1, m - 1);
    }
}

void main(void)
{
    int m;
    int x1, y1, x2, y2, x3, y3;
    x1 = 13;
    x2 = 40;
    x3 = 67;
    y1 = y2 = y3 = 24;
    textmode(C80);
    clrscr();
    printf("\nSo tang: ");
    scanf("%d", &m);
    printf("\nTime delay: ");
    scanf("%d", &t);
    textbackground(bg);
    clrscr();
    tower(x1, y1, m);
        getch();
    movetower(x1, y1, x2, y2, x3, y3, m);
    getch();
    window(1, 1, 80, 25);
    textbackground(bg);
    textcolor(WHITE);
    clrscr();

}

Thứ Năm, 24 tháng 12, 2015

Chương trình xử lí chuỗi cơ bản.


#include<stdio.h>
#include<conio.h>
#include<ctype.h>

void info(char a[], int &leng)
{
    char ten[20], que[20];
    int i = 0;
    leng = 0;
    printf("\nNhap ten: ");
    gets(ten);
    printf("\nNhap que: ");
    gets(que);

    while (ten[i] != '\0')
    {
        if (ten[i] != ' ')
            a[leng++] = tolower(ten[i++]);
        else
        {
            i++;
            continue;
        }
    }
    i = 0;
    while (que[i] != '\0')
    {
        if (que[i] != ' ')
            a[leng++] = tolower(que[i++]);
        else
        {
            i++;
            continue;
        }
    }
    a[leng] = '\0';

    printf("\nChuyen het thanh 1 day ki tu thuong: %s", a);
}

void swap(char &a, char &b)
{
    char c = a;
    a = b;
    b = c;
}

void sxtang(char a[], int leng)
{
    for (int i = 0; i < leng - 1; i++)
        for (int j = i + 1; j < leng; j++)
            if (a[i]>a[j])
                swap(a[i], a[j]);
    printf("\nDay ki sau khi sx tang: %s", a);
}

int dem(char a[], char x)
{
    int dem = 0, i = 0;
    while (a[i] != '\0')
    {
        if (a[i++] == x)
            dem++;
    }
    return dem;
}

void solanxuathien(char a[], int leng)
{
    int x;
    int max = dem(a, a[0]);
    for (int i = 0; i < leng; i++)
    {
        if (a[i] == a[i + 1])
            continue;
        x = dem(a, a[i]);
        printf("\n%c xuat hien %d lan", a[i], x);
          
        if (max < x)
            max = x;
    }

    for (int i = 0; i < leng; i++)
    {
        if (a[i] == a[i + 1])
            continue;
        x = dem(a, a[i]);
        if (x == max)
            printf("\nKi tu xuat hien nhieu nhat la: %c", a[i]);
    }
}

void chuyenhoa(char a[], int leng)
{
    for (int i = 0; i < leng; i++)
        a[i] = toupper(a[i]);
    printf("\nChuoi chuyen thanh ki tu hoa: %s", a);
}

void main(void)
{
    char a[30];
    int leng;
    info(a, leng);
    sxtang(a, leng);
    solanxuathien(a, leng);
    chuyenhoa(a, leng);
    getch();
}

Thứ Sáu, 18 tháng 12, 2015

MS Visual Studio 2013 - Trình build code chuyên nghiệp

Khỏi phải bàn nhiều về thằng này, sản phẩm của ông lớn MS có thể code trên nhiều ngôn ngữ, đặc biệt là C và C++, dưới đây mình share link bản Ultimate 2013 chạy trên win 7, hiện tại mình đang dùng thì rất ổn, ai muốn thì có thể tìm đến bản 2015 nhưng yêu cần phải là win 8.1 trở lên, RAM tối thiểu là 2gb nhưng 4 gb mới ổn định, bạn nào vẫn còn một dạ với XP thì hay tìm các bản VS 2010 trở xuống nhé. Link từ MS nên không phải lo cái gì vớ vẩn.

Link: http://download.microsoft.com/download/C/F/B/CFBB5FF1-0B27-42E0-8141-E4D6DA0B8B13/VS2013_RTM_ULT_ENU.iso

Viết chương trình sử dụng danh sách liên kết đơn xử lí các công việc sau.

Công việc:
1. Nhập/xuất random danh sách các số nguyên gồm n số, mỗi số mới thêm vào cuối dánh sách.
2. Thêm vào đầu 1 số random.
3. Xóa số đầu danh sách.
4. Xóa 1 số sau số X đầu tiên tùy chọn (nếu có)
5. Xóa hết các số X tùy chọn.
6. Xóa 1 số sau số MIN đầu tiên (nếu được)
7. Xóa các số sau số MAX (nếu được)
8. Xóa hết các số MAX.
9. Xóa số gần kế cuối (nếu được)

CODE NÀY CHẠY CHUẨN TRÊN Visual Studio, NẾU CHẠY TRÊN Borland C THÌ SẼ PHẢI FIX MỘT VÀI CHỖ !


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

typedef struct node
{
int info;
node *next;
};

node *getnode(int x)
{
node *p = new node;
if (!p) return NULL;
p->info = x;
p->next = NULL;
return p;
}

void addtail(node *&h, node *&t, int x)
{
node *p = getnode(x);
if (!h) h = t = p;
else
{
t->next = p;
t = p;
}
}

void addhead(node *&h, node *&t, int x)
{
node *p = getnode(x);
if (!h) h = t = p;
else
{
p->next = h;
h = p;
}
}

void delhead(node*&h, node *&t)
{
if (!h) return;
node *p = h;
h = h->next;
delete p;
if (!h) t = NULL;
}

node *search(node *h, int x)
{
node *p = h;
while (p && p->info != x)
p = p->next;
return p;
}

void delafterX(node *q, node *&t)
{
node *p = q->next;
q->next = p->next;
delete p;
if (q->next == NULL)
t = q;
}

void delX(node *&h, node *&t, int x)
{
if (h->info == x)
{
delhead(h, t);
return;
}
node *p = h;
while (p->next != NULL && p->next->info != x)
p = p->next;
if (p->next->info == x)
delafterX(p, t);
}

int min(node *h)
{
int min = h->info;
for (node *p = h; p; p=p->next)
if (min > p->info)
min = p->info;
return min;
}

int max(node *h)
{
int max = h->info;
for (node *p = h; p; p = p->next)
if (max < p->info)
max = p->info;
return max;
}

//

void list(node *&h, node *&t)
{
int x, n;
do
{
printf("\nNhap so phan tu: ");
scanf("%d", &n);
if (n < 0)
printf("\nNhap sai, nhap lai.");
} while (n < 0);

for (int i = 0; i < n; i++)
{

x = rand() % 10;
addtail(h, t, x);
}

}

void xuat(node *h)
{
printf("\nDanh sach hien tai: ");
if (!h)
{
printf("Rong!");
return;
}

for (node *p = h; p; p = p->next)
printf("%5d", p->info);
}

void themdau(node *&h, node *&t)
{
int x;
printf("\nNhap so muon them vao dau: ");
scanf("%d", &x);
addhead(h, t, x);
}

void xoadau(node *&h, node *&t)
{
printf("\nDa xoa 1 phan tu dau danh sach !");
delhead(h, t);
}

void xoasauX(node *h, node *&t)
{
int x;
node *q;
printf("\nNhap so can tim: ");
scanf("%d", &x);
q = search(h, x);
if (q && q != t)
{
printf("\nDa xoa phan tu sau X !");
delafterX(q, t);
}
else printf("\nKhong tim thay hoac X la phan tu cuoi cung !");
}

void xoahetX(node *&h, node *&t)
{
int x;
printf("\nNhap so can tim: ");
scanf("%d", &x);
node *p = h;
while (p)
{
if (p->info == x)
{
p = p->next;
delX(h, t, x);
continue;
}
p = p->next;
}
}

void xoasaumin(node *h, node *&t)
{
int Min = min(h);
node *p = search(h, Min);
if (p && p != t)
{
printf("\nDa xoa 1 phan tu sau min dau tien!");
delafterX(p, t);
}
else printf("\nMin la tail !");

}

void xoahetsaumax(node *h, node *&t)
{
int Max = max(h);
node *p = h;
while (p && p!=t)
{
if (p->info == Max)
delafterX(p, t);
p = p->next;
}
}

void xoahetmax(node *&h, node *&t)
{
int Max = max(h);
node *p = h;
while (p && p != t)
while (p)
{
if (p->info == Max)
{
p = p->next;
delX(h, t, Max);
continue;
}
p = p->next;
}
}

void xoasogancuoi(node *&h, node *t)
{
if (!h && h == t) return;
if (h->next == t)
{
delhead(h, t);
return;
}
node *p = h;
while (p->next->next != t)
p = p->next;
delafterX(p, t);

}

////////////////////////////////////
void main(void)
{
node *h = NULL;
node *t = NULL;
list(h, t);
xuat(h);
themdau(h, t);
xuat(h);

xoadau(h, t);
xuat(h);

xoasauX(h, t);
xuat(h);

xoahetX(h, t);
xuat(h);

xoasaumin(h, t);
xuat(h);

xoahetsaumax(h, t);
xuat(h);

xoahetmax(h, t);
xuat(h);

xoasogancuoi(h, t);
xuat(h);
getch();
}

Thứ Tư, 16 tháng 12, 2015

Chương trình tổng hợp các bài về danh sách liên kết đơn kiểu cấu trúc

 CODE NÀY CHẠY CHUẨN TRÊN Visual Studio, NẾU CHẠY TRÊN Borland C THÌ SẼ PHẢI FIX MỘT VÀI CHỖ !
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>

int dem = 0;

//Tạo kiểu cấu trúc
typedef struct SV
{
    int stt;
    long ms;
    char ten[41];
    float dtb;
    char sex;
};

typedef struct node
{
    SV info;
    node *next;
};

//Tạo các hàm xử lí danh sách lkđ cơ bản
node *getnode(SV x)
{
    node *p = new node;
    if (!p)    return NULL;
    p->info = x;
    p->next = NULL;
    return p;
}

void addhead(node *&h, node *&t, SV x)
{
    node *p = getnode(x);
    if (!h)    h = t = p;
    else
    {
        p->next = h;
        h = p;
    }
}

void addtail(node *&h, node *&t, SV x)
{
    node *p = getnode(x);
    if (!h)    h = t = p;
    else
    {
        t->next = p;
        t = p;
    }
}

void addafter(node *q, node *&t, SV x)
{
    node *p = getnode(x);
    p->next = q->next;
    q->next = p;
    if (q == t)
        t = p;
}

void delhead(node *&h, node *&t)
{
    node *p = h;
    if (!h)    return;
    h = h->next;
    delete p;
    if (!h)    t = NULL;
}

void delafter(node *q, node *&t)
{
    node *p = q->next;
    q->next = p->next;
    delete p;
    if (q->next == NULL)
        t = q;
}

void delall(node *&h, node *&t)
{
    node *p = h;
    while (h)
    {
        p = h;
        h = h->next;
        delete p;
    }
    t = NULL;
}

void deltail(node *&h, node *&t)
{
    if (!h)    return;
    node *p = h;
    node *r = t;
    if (h == t)
    {
        h = t = NULL;
        delete p;
        delete r;
    }
    else
    {
        while (p->next != r) p = p->next;
        p->next = NULL;
        t = p;
        delete r;
    }
}

node *searchMS(node *h, long x)
{
    node *p = h;
    while (p && p->info.ms != x)
        p = p->next;
    return p;
}

node *searchTEN(node *h, char a[])
{
    node *p = h;
    while (p && strcmp(p->info.ten, a) != 0)
        p = p->next;
    return p;
}

//Các hàm xử lí linh tinh
void nhap1sv(SV &a)
{
    dem++;
    a.stt = dem;
    printf("\nNhap MSSV: ");
    scanf("%lo", &a.ms);
    fflush(stdin);
    printf("Nhap ho ten: ");
    gets(a.ten);
    fflush(stdin);
    printf("Nhap DTB: ");
    scanf("%f", &a.dtb);
    fflush(stdin);
    do
    {
        printf("Nhap gioi tinh (M/F): ");
        scanf("%c", &a.sex);
        fflush(stdin);
        if (a.sex != 'M' && a.sex != 'F')
            printf("\nNhap sai nhap lai !");
    } while (a.sex != 'M' && a.sex != 'F');
}

void xuat1sv(SV a)
{
    printf("\n\t\t|MSSV: %lo", a.ms);
    printf("\nSV %d",a.stt);
    printf("\t\t|Ten: %s", a.ten);
    printf("\n\t\t|DTB: %.3f", a.dtb);
    if (a.sex == 'F')
        printf("\n\t\t|Gioi tinh: NU");
    else printf("\n\t\t|Gioi tinh: NAM");
    printf("\n");
}

void list(node *&h, node *&t)
{
    int n;
    SV x;
    do
    {
        printf("\nNhap so luong SV: ");
        scanf("%d", &n);
        if (n < 0)    printf("\nNhap sai. Nhap lai !");
    } while (n < 0);
    for (int i = 0; i < n; i++)
    {
        printf("\n------Nhap SV thu %d------", i + 1);
        nhap1sv(x);
        addtail(h, t, x);
        printf("\n");
    }
}

void xuat(node *h)
{
    for (node *p = h; p; p = p->next)
        xuat1sv(p->info);
}

void themdau(node *&h, node *&t)
{
    SV x;
    nhap1sv(x);
    addhead(h, t, x);
}

void themcuoi(node *&h, node *&t)
{
    SV x;
    nhap1sv(x);
    addtail(h, t, x);
}

void themsauTEN(node *&h, node *&t)
{
    SV x;
    node *q;
    char a[41];
    fflush(stdin);
    printf("\nNhap ten can tim: ");
    gets(a);
    q = searchTEN(h, a);
    if (q)
    {
        printf("\nTim thay ! Day la SV so %d\n\n", q->info.stt);
        puts("--NHAP THONG TIN SV MOI--");
        nhap1sv(x);
        addafter(q, t, x);
        dem = 1;
        for (node *p = h; p; p = p->next)
        {
            p->info.stt = dem;
            dem++;
        }
        printf("\nBan vua them 1 SV vao sau SV %d thanh cong ! Danh sach hien tai la:", q->info.stt);
        if (h)
            xuat(h);
        else printf("\n RONG !");
        getch();
    }
    else
    {
        puts("Khong tim thay !");
        getch();
    }
}

void xoaq(node *&h, node *&t)
{
    node *q;
    char a[41];
    fflush(stdin);
    printf("\nNhap ten can tim: ");
    gets(a);
    q = searchTEN(h, a);
    node *p = h;
    if (q == h)
    {
        printf("Ban vua xoa SV dau tien co ten la %s ! Danh sach hien tai la:", h->info.ten);
        delhead(h, t);
        return;
    }
    if (q == t)
    {
        printf("Ban vua xoa SV cuoi cung co ten la %s ! Danh sach hien tai la:", t->info.ten);
        deltail(h, t);
        return;
    }
    while (p && p->next != q)
        p = p->next;
    p->next = q->next;
    printf("Ban vua xoa SV co ten la %s ! Danh sach hien tai la:", q->info.ten);
    delete q;
}

void xoasauTEN(node *&h, node *&t)
{
    node *q;
    char a[41];
    fflush(stdin);
    printf("\nNhap ten can tim: ");
    gets(a);
    q = searchTEN(h, a);
    if (q && q != t)
    {
        printf("\nTim thay ! Day la SV so %d\n\n", q->info.stt);
        printf("\nBan vua xoa SV ten %s ! Danh sach hien tai la: ", q->next->info.ten);
        delafter(q, t);
        dem = 1;
        for (node *p = h; p; p = p->next)
        {
            p->info.stt = dem;
            dem++;
        }
        if (h)
            xuat(h);
        else printf("\n RONG !");
        getch();
    }
    else
    {
        puts("Khong tim thay !");
        getch();
    }
}

void main(void)
{
    node *h = NULL;
    node *t = NULL;
    node *q;
    int chon;
    puts("** TAO DANH SACH SINH VIEN SU DUNG DANH SACH LIEN KET DON **");
    list(h, t);
    system("cls");
    puts("---DANH SACH CAC SINH VIEN VUA MOI TAO---");
    xuat(h);
    puts("Nhan phim bat ki de tiep tuc !");
    getch();
back:
    system("cls");
    puts("---MENU XU LY DANH SACH LIEN KET DON---");
    puts("1. Xem danh sach hien tai.");
    puts("2. Them 1 SV vao dau danh sach.");
    puts("3. Them 1 SV vao cuoi danh sach.");
    puts("4. Them 1 SV ngay sau 1 SV cho truoc.");
    puts("5. Xoa SV dau danh sach.");
    puts("6. Xoa SV cuoi danh sach.");
    puts("7. Xoa 1 SV sau 1 SV cho truoc.");
    puts("8. Xoa 1 SV bat ki.");
    puts("9. Tim kiem 1 SV theo ten.");
    puts("10. Tim kiem 1 SV theo MSSV.");
    puts("");
    printf("\nChon 1 muc: ");
    scanf("%d", &chon);
    switch (chon)
    {
    case 1:
        system("cls");
        puts("--DANH SACH CAC SV HIEN TAI--");
        if (h)
            xuat(h);
        else printf("\n RONG !");
        getch();
        goto back;
    case 2:
        system("cls");
        puts("--NHAP THONG TIN SV MOI--");
        themdau(h, t);
        dem = 1;
        for (node *p = h; p; p = p->next)
        {
            p->info.stt = dem;
            dem++;
        }
        printf("\nBan vua them 1 SV vao dau danh sach thanh cong ! Danh sach hien tai la:");
        if (h)
        xuat(h);
        else printf("\n RONG !");
        getch();
        goto back;
    case 3:
        system("cls");
        puts("--NHAP THONG TIN SV MOI--");
        themcuoi(h, t);
        dem = 1;
        for (node *p = h; p; p = p->next)
        {
            p->info.stt = dem;
            dem++;
        }
        printf("\nBan vua them 1 SV vao cuoi danh sach thanh cong ! Danh sach hien tai la:");
        if (h)
            xuat(h);
        else printf("\n RONG !");
        getch();
        goto back;
    case 4:
        system("cls");
        puts("--TIM TEN SINH VIEN DE THEM VAO SAU--");
        themsauTEN(h, t);
        goto back;
    case 5:
        system("cls");
        printf("Ban vua xoa SV dau tien co ten la %s ! Danh sach hien tai la:", h->info.ten);
        delhead(h, t);
        dem = 1;
        for (node *p = h; p; p = p->next)
        {
            p->info.stt = dem;
            dem++;
        }
        if (h)
            xuat(h);
        else printf("\n RONG !");
        getch();
        goto back;
    case 6:
        system("cls");
        printf("Ban vua xoa SV cuoi cung co ten la %s ! Danh sach hien tai la:", t->info.ten);
        deltail(h, t);
        dem = 1;
        for (node *p = h; p; p = p->next)
        {
            p->info.stt = dem;
            dem++;
        }
        if (h)
            xuat(h);
        else printf("\n RONG !");
        getch();
        goto back;
    case 7:
        system("cls");
        xoasauTEN(h, t);
        goto back;
    case 8:
        system("cls");
        xoaq(h, t);
        dem = 1;
        for (node *p = h; p; p = p->next)
        {
            p->info.stt = dem;
            dem++;
        }
        if (h)
            xuat(h);
        else printf("\n RONG !");
        getch();
        goto back;
    case 9:
       
        char a[41];
        fflush(stdin);
        printf("\nNhap ten can tim: ");
        gets(a);
        q = searchTEN(h, a);
        if (q)
            printf("\nTim Thay !");
        else printf("\nKhong tim thay !");
        getch();
        goto back;
    case 10:
       
        long x;
        fflush(stdin);
        printf("\nNhap MSSV can tim: ");
        scanf("%lo", &x);
        q = searchMS(h, x);
        if (q)
            printf("\nTim Thay !");
        else printf("\nKhong tim thay !");
        getch();
        goto back;
       
       
    }
    getch();
}

Thứ Ba, 15 tháng 12, 2015

Chương trình tổng hợp các bài cơ bản của danh sách liên kết đơn SỐ NGUYÊN

 CODE NÀY CHẠY CHUẨN TRÊN Visual Studio, NẾU CHẠY TRÊN Borland C THÌ SẼ PHẢI FIX MỘT VÀI CHỖ !
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

typedef struct node  //tạo kiểu của danh sách liên kết đơn
{
    int info;
    node *next;
};

node *getnode(int x)  //tạo nút mới
{
    node *p = new node;
    if (!p)    return NULL;
    p->info = x;
    p->next = NULL;
    return p;
}

void addhead(node *&h, node *&t, int x)  //thêm vào đầu danh sách
{
    node *p = getnode(x);
    if (!h)
        h = t = p;
    else
    {
        p->next = h;
        h = p;
    }
}

void addtail(node *&h, node *&t, int x) //thêm vào cuối danh sách
{
    node *p = getnode(x);
    if (!h)
        h = t = p;
    else
    {
        t->next = p;
        t = p;
    }
}

void addafter(node *q, node *&t, int x) //thêm nút vào sau 1 nút
{
    node *p = getnode(x);
    p->next = q->next;
    q->next = p;
    if (q == t)
        t = p;
}

void delhead(node *&h, node *&t) //xóa nút đầu danh sách
{
    if (!h)    return;
    node *p = h;
    h = p->next;
    delete p;
    if (!h)    t = NULL;
}

void delafter(node *q, node *&t) //xóa nút sau 1 nút
{
    node *p = q->next;
    q->next = p->next;
    delete p;
    if (q->next == NULL)
        t = q;
}

node *search(node *h, int x)
{
    node *p = h;
    while (p && p->info != x)
        p = p->next;
    return p;
}

void list(node *&h, node *&t) //tạo danh sách random
{
    int n, x;
    do
    {
        printf("\nNhap so phan tu: ");
        scanf("%d", &n);
        if (n < 0)
            printf("\nNhap sai. Nhap lai.");
    } while (n < 0);
    for (int i = 0; i < n; i++)
    {
        x = rand() % 10;  //Random số từ 0 - 10
        addtail(h, t, x);
    }
}

void xuat(node *h) //xuất danh sách
{
    for (node *p = h; p; p = p->next)
        printf("%5d", p->info);
}

void themtruoc(node *&h, node *&t)
{
    int x = rand() % 10;
    addhead(h, t, x);
    printf("\nBan vua them so %d vao dau danh sach !", x);
}

void themcuoi(node *&h, node *&t)
{
    int x = rand() % 10;
    addtail(h, t, x);
    printf("\nBan vua them so %d vao cuoi danh sach !", x);
}

void themsaux(node *h, node *t)
{
    int x, s;
    node *p;
    printf("\nNhap so can tim de them vao sau: ");
    scanf("%d", &x);
    p = search(h, x);
    if (p)
    {
        s = rand() % 10;
        printf("\nBan vua them sau so %d so %d", x, s);
        addafter(p, t, s);
    }
    else
        printf("\nKhong the them duoc vi tim khong thay so can tim !");
   
}

void xoasaux(node *h, node *&t)
{
    int x;
    node *p;
    printf("\nNhap so can tim de xoa so sau no: ");
    scanf("%d", &x);
    p = search(h, x);
    if (p && p != t)
    {
        printf("\nBan xoa so %d", p->next->info);
        delafter(p, t);
    }
    else
        printf("\nKhong the xoa duoc vi tim khong thay so can tim hoac da o cuoi danh sach !");

}

void xoacuoi(node *&h, node *&t)
{
    if (!h)
    {
        return;
    }
    node *p = h;
    node *r = t;
    if (p == r)
    {
        h = t = NULL;
        delete p;
    }
    else
    {
        while (p->next != r) p = p->next;
        p->next = NULL;
        t = p;
        delete r;
    }
}

void xoahet(node *&h, node *&t)
{
    node *p;
    while (h)
    {
        p = h;
        h = h->next;
        delete p;
    }
    t = NULL;
}

void xoax(node *&h, node *&t)
{
    int x;
    node *p;
    printf("\nNhap so can tim de xoa: ");
    scanf("%d", &x);
    p = search(h, x);
    if (!p)
    {
        printf("\nDeo thay, deo xoa.");
        return;
    }
    if (p == h)
    {
        printf("\nBan vua xoa so %d !", h->info);
        delhead(h, t);
        return;
    }
    if (p == t)
    {
        printf("\nBan vua xoa so %d !", t->info);
        xoacuoi(h, t);
        return;
    }
    for (node *q = h; q; q->next)
        if (q->next == p)
        {
            q->next = p->next;
            p->next = NULL;
            printf("\nBan vua xoa so %d !", p->info);
            delete p;
            return;
        }
   
}

void main(void)
{
    node *h = NULL;
    node *t = NULL;
    int chon;
    puts("----TAO DANH SACH LIEN KET----");
    list(h, t);
    puts("Cac phan tu vua duoc tao la:\n ");
    xuat(h);
    puts("\n\nEnter de tiep tuc !");
    getch();
back:
    system("cls");
    printf("\nDANH SACH HIEN TAI: ");
    if (!h)
        printf("RONG !");
    else
    xuat(h);
    puts("\n\n----MENU CHUONG TRINH THUC HIEN CAC THAO TAC CUA DANH SACH LIEN KET DON----");
    puts("1. Them ngau nhien 1 so vao dau danh sach.");
    puts("2. Them ngau nhien 1 so vao cuoi danh sach.");
    puts("3. Them ngau nhien 1 so sau 1 so cho truoc.");
    puts("4. Xoa so dau tien cua danh sach.");
    puts("5. Xoa 1 so sau 1 so cho truoc.");
    puts("6. Xoa so cuoi cung cua danh sach.");
    puts("7. Xoa het danh sach.");
    puts("8. Xoa 1 so cho truoc.");
    printf("\nChon 1 so: ");
    scanf("%d", &chon);
    switch (chon)
    {
    case 1:
        system("cls");
        themtruoc(h, t);
        puts("\nDanh sach hien tai la: \n");
        if (!h)
            printf("RONG !");
        else
            xuat(h);
        getch();
        goto back;
    case 2:
        system("cls");
        themcuoi(h, t);
        puts("\nDanh sach hien tai la: \n");
        if (!h)
            printf("RONG !");
        else
            xuat(h);
        getch();
        goto back;
    case 3:
        system("cls");
        themsaux(h, t);
        puts("\nDanh sach hien tai la: \n");
        if (!h)
            printf("RONG !");
        else
            xuat(h);
        getch();
        goto back;
    case 4:
        system("cls");
        printf("\nBan vua xoa so %d !", h->info);
        delhead(h, t);
        puts("\nDanh sach hien tai la: \n");
        if (!h)
            printf("RONG !");
        else
            xuat(h);
        getch();
        goto back;
    case 5:
        system("cls");
        xoasaux(h, t);
        puts("\nDanh sach hien tai la: \n");
        if (!h)
            printf("RONG !");
        else
            xuat(h);
        getch();
        goto back;
    case 6:
        system("cls");
        if (!h)
            printf("\nXoa cung nhu khong !");
        else
        printf("\nBan vua xoa so %d", t->info);
        xoacuoi(h, t);
        puts("\nDanh sach hien tai la: \n");
        if (!h)
            printf("RONG !");
        else
            xuat(h);
        getch();
        goto back;
    case 7:
        system("cls");
        if (!h)
            printf("\nXoa cung nhu khong !");
        else
            printf("\nXoa het cmnr !");
        xoahet(h, t);
        puts("\nDanh sach hien tai la: \n");
        if (!h)
            printf("RONG !");
        else
            xuat(h);
        getch();
        goto back;
    case 8:
        system("cls");
        xoax(h, t);
        puts("\nDanh sach hien tai la: \n");
        if (!h)
            printf("RONG !");
        else
            xuat(h);
        getch();
        goto back;
    }


    getch();
}

Chương trình tập hợp các bài sắp xếp và các kiểu sắp xếp theo cấu trúc.

 CODE NÀY CHẠY CHUẨN TRÊN Visual Studio, NẾU CHẠY TRÊN Borland C THÌ SẼ PHẢI FIX MỘT VÀI CHỖ !
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>

#define MAX 100

typedef struct nv
{
    int ms;
    char ten[20];
    float luong;
};

void nhapn(int &n)
{
    do
    {
        printf("\nNhap so NV: ");
        scanf("%d", &n);
        if (n < 1)    printf("\nNhap sai. Nhap lai.");
    } while (n < 1);
}

void nhap(nv &a)
{
    printf("\nNhap ma so: ");
    scanf("%d",&a.ms);
    fflush(stdin);
    printf("\nNhap ten: ");
    gets(a.ten);
    fflush(stdin);
    printf("\nNhap luong: ");
    scanf("%f", &a.luong);
    fflush(stdin);
}

void xuat(nv &a)
{
    printf("\nMS: %d", a.ms);
    printf("\nTen: %s", a.ten);
    printf("\nLuong: %.3f", a.luong);
}

void nhapnv(nv a[], int n)
{
    printf("\n\n---------------HAY NHAP CAC NHAN VIEN---------------");
    for (int i = 0; i < n; i++)
        nhap(a[i]);
}

void xuatnv(nv a[], int n)
{
    for (int i = 0; i < n; i++)
    {
        xuat(a[i]);
        printf("\n");
    }
}

void swap(nv &a, nv &b)
{
    nv c = a;
    a = b;
    b = c;
}

void InterchangeSortUpMS(nv a[], int n)
{
    for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++)
    if (a[i].ms > a[j].ms)
        swap(a[i], a[j]);
}

void InterchangeSortDownMS(nv a[], int n)
{
    for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++)
    if (a[i].ms < a[j].ms)
        swap(a[i], a[j]);
}

void InterchangeSortUpTEN(nv a[], int n)
{
    for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++)
    if (strcmp(a[i].ten,a[j].ten)==1)
        swap(a[i], a[j]);
}

void InterchangeSortDownTEN(nv a[], int n)
{
    for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++)
    if (strcmp(a[i].ten,a[j].ten)==-1)
        swap(a[i], a[j]);
}

void BubbleSortUpMS(nv a[], int n)
{
    for (int i = 0; i < n - 1; i++)
    for (int j = n-1; j >i; j--)
    if (a[j].ms > a[j-1].ms)
        swap(a[j-1], a[j]);
}

void BubbleSortDownMS(nv a[], int n)
{
    for (int i = 0; i < n - 1; i++)
    for (int j = n - 1; j >i; j--)
    if (a[j].ms < a[j - 1].ms)
        swap(a[j], a[j - 1]);
}

void BubbleSortDownTEN(nv a[], int n)
{
    for (int i = 0; i < n - 1; i++)
    for (int j = n - 1; j >i; j--)
    if (strcmp(a[j].ten, a[j - 1].ten)==1)
        swap(a[j - 1], a[j]);
}

void BubbleSortUpTEN(nv a[], int n)
{
    for (int i = 0; i < n - 1; i++)
    for (int j = n - 1; j >i; j--)
    if (strcmp(a[j - 1].ten,a[j].ten)==1)
        swap(a[j], a[j - 1]);
}

void SelectionSortUpMS(nv a[], int n)
{
    int i;
    for (i = 0; i < n - 1; i++)
    {
        int vtmin = i;
        for (int j = i + 1; j < n; j++)
        if (a[j].ms < a[vtmin].ms)
            vtmin = j;
        swap(a[vtmin], a[i]);
    }
}

void SelectionSortDownMS(nv a[], int n)
{
    int i;
    for (i = 0; i < n - 1; i++)
    {
        int vtmax = i;
        for (int j = i + 1; j < n; j++)
        if (a[j].ms > a[vtmax].ms)
            vtmax = j;
        swap(a[vtmax], a[i]);
    }
}

void SelectionSortUpTEN(nv a[], int n)
{
    int i;
    for (i = 0; i < n - 1; i++)
    {
        int vtmin = i;
        for (int j = i + 1; j < n; j++)
        if (strcmp(a[j].ten, a[vtmin].ten)==-1)
            vtmin = j;
        swap(a[vtmin], a[i]);
    }
}

void SelectionSortDownTEN(nv a[], int n)
{
    int i;
    for (i = 0; i < n - 1; i++)
    {
        int vtmin = i;
        for (int j = i + 1; j < n; j++)
        if (strcmp(a[j].ten, a[vtmin].ten) == 1)
            vtmin = j;
        swap(a[vtmin], a[i]);
    }
}

void InsertionSortUpMS(nv a[], int n)
{
    int pos;
    nv x;
    for (int i = 1; i < n; i++)
    {
        x = a[i];
        pos = i - 1;
        while (pos >= 0 && a[pos].ms>x.ms)
        {
            a[pos + 1] = a[pos];
            pos--;
        }
        a[pos + 1] = x;
    }
}

void InsertionSortDownMS(nv a[], int n)
{
    int pos;
    nv x;
    for (int i = 1; i < n; i++)
    {
        x = a[i];
        pos = i - 1;
        while (pos >= 0 && a[pos].ms<x.ms)
        {
            a[pos + 1] = a[pos];
            pos--;
        }
        a[pos + 1] = x;
    }
}

void InsertionSortUpTEN(nv a[], int n)
{
    int pos;
    nv x;
    for (int i = 1; i < n; i++)
    {
        x = a[i];
        pos = i - 1;
        while (pos >= 0 && strcmp(a[pos].ten,x.ten)==1)
        {
            a[pos + 1] = a[pos];
            pos--;
        }
        a[pos + 1] = x;
    }
}

void InsertionSortDownTEN(nv a[], int n)
{
    int pos;
    nv x;
    for (int i = 1; i < n; i++)
    {
        x = a[i];
        pos = i - 1;
        while (pos >= 0 && strcmp(a[pos].ten, x.ten) == -1)
        {
            a[pos + 1] = a[pos];
            pos--;
        }
        a[pos + 1] = x;
    }
}

void ShellSortUpMS(nv a[], int n, int h[], int k)
{
    int count = 0;
    int step, i, pos, len;
    nv x;
    for (step = 0; step < k; step++)
    {
        len = h[step];
        for (i = len; i<n; i++)
        {
            x = a[i];
            pos = i - len;
            while ((x.ms < a[pos].ms) && (pos >= 0))
            {
                a[pos + len] = a[pos];
                pos = pos - len;
                count++;
            }
            a[pos + len] = x;
        }

    }
}

void ShellSortDownMS(nv a[], int n, int h[], int k)
{
    int count = 0;
    int step, i, pos, len;
    nv x;
    for (step = 0; step < k; step++)
    {
        len = h[step];
        for (i = len; i<n; i++)
        {
            x = a[i];
            pos = i - len;
            while ((x.ms > a[pos].ms) && (pos >= 0))
            {
                a[pos + len] = a[pos];
                pos = pos - len;
                count++;
            }
            a[pos + len] = x;
        }

    }
}

void ShellSortUpTEN(nv a[], int n, int h[], int k)
{
    int count = 0;
    int step, i, pos, len;
    nv x;
    for (step = 0; step < k; step++)
    {
        len = h[step];
        for (i = len; i<n; i++)
        {
            x = a[i];
            pos = i - len;
            while (strcmp(x.ten , a[pos].ten)==-1 && (pos >= 0))
            {
                a[pos + len] = a[pos];
                pos = pos - len;
                count++;
            }
            a[pos + len] = x;
        }

    }
}

void ShellSortDownTEN(nv a[], int n, int h[], int k)
{
    int count = 0;
    int step, i, pos, len;
    nv x;
    for (step = 0; step < k; step++)
    {
        len = h[step];
        for (i = len; i<n; i++)
        {
            x = a[i];
            pos = i - len;
            while (strcmp(x.ten, a[pos].ten) == 1 && (pos >= 0))
            {
                a[pos + len] = a[pos];
                pos = pos - len;
                count++;
            }
            a[pos + len] = x;
        }

    }
}

void QuickSortUpMS(nv a[], int l, int r)
{
    if (l >= r) return;
    int i = l;
    int j = r;
    nv x = a[(l + r) / 2];//x=A[random(l-r)]
    while (i <= j)
    {
        while (a[i].ms<x.ms) i++;
        while (a[j].ms>x.ms) j--;
        if (i <= j)
        {
            swap(a[i], a[j]);
            i++; j--;
        }
    }
    QuickSortUpMS(a, l, j);
    QuickSortUpMS(a, i, r);

}

void QuickSortDownMS(nv a[], int l, int r)
{
    if (l >= r) return;
    int i = l;
    int j = r;
    nv x = a[(l + r) / 2];//x=A[random(l-r)]
    while (i <= j)
    {
        while (a[i].ms>x.ms) i++;
        while (a[j].ms<x.ms) j--;
        if (i <= j)
        {
            swap(a[i], a[j]);
            i++; j--;
        }
    }
    QuickSortDownMS(a, l, j);
    QuickSortDownMS(a, i, r);

}

void QuickSortUpTEN(nv a[], int l, int r)
{
    if (l >= r) return;
    int i = l;
    int j = r;
    nv x = a[(l + r) / 2];//x=A[random(l-r)]
    while (i <= j)
    {
        while (strcmp(a[i].ten,x.ten)==-1) i++;
        while (strcmp(a[j].ten,x.ten)==1) j--;
        if (i <= j)
        {
            swap(a[i], a[j]);
            i++; j--;
        }
    }
    QuickSortUpTEN(a, l, j);
    QuickSortUpTEN(a, i, r);

}

void QuickSortDownTEN(nv a[], int l, int r)
{
    if (l >= r) return;
    int i = l;
    int j = r;
    nv x = a[(l + r) / 2];//x=A[random(l-r)]
    while (i <= j)
    {
        while (strcmp(a[i].ten,x.ten)==1) i++;
        while (strcmp(a[j].ten,x.ten)==-1) j--;
        if (i <= j)
        {
            swap(a[i], a[j]);
            i++; j--;
        }
    }
    QuickSortDownTEN(a, l, j);
    QuickSortDownTEN(a, i, r);

}

void MergeSortUpMS(nv a[], int n)
{
    int i, j, k, low1, up1, low2, up2, size;
    nv dstam[MAX];
    size = 1;
    while (size <n)
    {
        low1 = 0;
        k = 0;
        while (low1 + size < n)
        {
            low2 = low1 + size;
            up1 = low2 - 1;
            up2 = (low2 + size - 1 < n) ? (low2 + size - 1) : (n - 1);
            for (i = low1, j = low2; i <= up1 && j <= up2; k++)
            if (a[i].ms <= a[j].ms)    dstam[k] = a[i++];
            else                    dstam[k] = a[j++];
            for (; i <= up1; k++)    dstam[k] = a[i++];
            for (; j <= up2; k++)  dstam[k] = a[j++];
            low1 = up2 + 1;
        }
        for (i = low1; k<n; i++)        dstam[k++] = a[i];
        for (i = 0; i<n; i++)     a[i] = dstam[i];
        size *= 2;
    }
}

void MergeSortDownMS(nv a[], int n)
{
    int i, j, k, low1, up1, low2, up2, size;
    nv dstam[MAX];
    size = 1;
    while (size <n)
    {
        low1 = 0;
        k = 0;
        while (low1 + size < n)
        {
            low2 = low1 + size;
            up1 = low2 - 1;
            up2 = (low2 + size - 1 < n) ? (low2 + size - 1) : (n - 1);
            for (i = low1, j = low2; i <= up1 && j <= up2; k++)
            if (a[i].ms >= a[j].ms)    dstam[k] = a[i++];
            else                    dstam[k] = a[j++];
            for (; i <= up1; k++)    dstam[k] = a[i++];
            for (; j <= up2; k++)  dstam[k] = a[j++];
            low1 = up2 + 1;
        }
        for (i = low1; k<n; i++)        dstam[k++] = a[i];
        for (i = 0; i<n; i++)     a[i] = dstam[i];
        size *= 2;
    }
}

void MergeSortUpTEN(nv a[], int n)
{
    int i, j, k, low1, up1, low2, up2, size;
    nv dstam[MAX];
    size = 1;
    while (size <n)
    {
        low1 = 0;
        k = 0;
        while (low1 + size < n)
        {
            low2 = low1 + size;
            up1 = low2 - 1;
            up2 = (low2 + size - 1 < n) ? (low2 + size - 1) : (n - 1);
            for (i = low1, j = low2; i <= up1 && j <= up2; k++)
            if (strcmp(a[i].ten, a[j].ten) == -1 || strcmp(a[i].ten, a[j].ten) == 0)   
                dstam[k] = a[i++];
            else                    dstam[k] = a[j++];
            for (; i <= up1; k++)    dstam[k] = a[i++];
            for (; j <= up2; k++)  dstam[k] = a[j++];
            low1 = up2 + 1;
        }
        for (i = low1; k<n; i++)        dstam[k++] = a[i];
        for (i = 0; i<n; i++)     a[i] = dstam[i];
        size *= 2;
    }
}

void MergeSortDownTEN(nv a[], int n)
{
    int i, j, k, low1, up1, low2, up2, size;
    nv dstam[MAX];
    size = 1;
    while (size <n)
    {
        low1 = 0;
        k = 0;
        while (low1 + size < n)
        {
            low2 = low1 + size;
            up1 = low2 - 1;
            up2 = (low2 + size - 1 < n) ? (low2 + size - 1) : (n - 1);
            for (i = low1, j = low2; i <= up1 && j <= up2; k++)
            if (strcmp(a[i].ten, a[j].ten) == 1 || strcmp(a[i].ten, a[j].ten) == 0)    dstam[k] = a[i++];
            else                    dstam[k] = a[j++];
            for (; i <= up1; k++)    dstam[k] = a[i++];
            for (; j <= up2; k++)  dstam[k] = a[j++];
            low1 = up2 + 1;
        }
        for (i = low1; k<n; i++)        dstam[k++] = a[i];
        for (i = 0; i<n; i++)     a[i] = dstam[i];
        size *= 2;
    }
}




void main(void)
{
    int n, chon, k = 3;
    int h[] = { 5, 3, 1 };
    nv a[MAX];
    nhapn(n);
    nhapnv(a, n);
    puts("Ban da nhap thanh cong Enter de tiep tuc!");
    getch();
back:
    system("cls");
    puts("---------------HAY CHON 1 TRONG CAC CONG VIEC SAU---------------");
    puts("1. Xuat danh sach cac nhan vien vua moi nhap.");
    puts("2. Sap xep danh sach tang dan theo Ma So - Interchange Sort.");
    puts("3. Sap xep danh sach giam dan theo Ma So - Interchange Sort.");
    puts("4. Sap xep danh sach tang dan theo Ten - Interchange Sort.");
    puts("5. Sap xep danh sach giam dan theo Ten - Interchange Sort.");
    puts("6. Sap xep danh sach giam dan theo Ma So - Bubble Sort.");
    puts("7. Sap xep danh sach tang dan theo Ma So - Bubble Sort.");
    puts("8. Sap xep danh sach tang dan theo Ten - Bubblee Sort.");
    puts("9. Sap xep danh sach giam dan theo Ten - Bubble Sort.");
    puts("10. Sap xep danh sach tang dan theo Ma so - Selection Sort.");
    puts("11. Sap xep danh sach giam dan theo Ma so - Selection Sort.");
    puts("12. Sap xep danh sach tang dan theo Ten - Selection Sort.");
    puts("13. Sap xep danh sach giam dan theo Ten - Selection Sort.");
    puts("14. Sap xep danh sach tang dan theo Ma so - Insertion Sort.");
    puts("15. Sap xep danh sach giam dan theo Ma so - Insertion Sort.");
    puts("16. Sap xep danh sach tang dan theo Ten - Insertion Sort.");
    puts("17. Sap xep danh sach giam dan theo Ten - Insertion Sort.");
    puts("18. Sap xep danh sach tang dan theo Ma so - Shell Sort.");
    puts("19. Sap xep danh sach giam dan theo Ma so - Shell Sort.");
    puts("20. Sap xep danh sach tang dan theo TEN - Shell Sort.");
    puts("21. Sap xep danh sach giam dan theo TEN - Shell Sort.");
    puts("22. Sap xep danh sach tang dan theo Ma so - Quick Sort.");
    puts("23. Sap xep danh sach giam dan theo Ma so - Quick Sort.");
    puts("24. Sap xep danh sach tang dan theo Ten - Quick Sort.");
    puts("25. Sap xep danh sach giam dan theo Ten - Quick Sort.");
    puts("26. Sap xep danh sach tang dan theo Ma so - Merge Sort.");
    puts("27. Sap xep danh sach giam dan theo Ma so - Merge Sort.");
    puts("28. Sap xep danh sach tang dan theo Ten - Merge Sort.");
    puts("29. Sap xep danh sach giam dan theo Ten - Merge Sort.");
    puts("0. Exit");
    printf("\nNhap 1 so: ");
    scanf("%d", &chon);
    switch (chon)
    {
    case 1:
        system("cls");
            puts("---XUAT DANH SACH NHAN VIEN---");
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 2:
        system("cls");
        puts("---SX DANH SACH NHAN VIEN TANG DAN THEO MA SO - INTERCHANGE SORT---");
            InterchangeSortUpMS(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 3:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN GIAM DAN THEO MA SO - INTERCHANGE SORT---");
            InterchangeSortDownMS(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 4:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN TANG DAN THEO TEN - INTERCHANGE SORT---");
            InterchangeSortUpTEN(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 5:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN GIAM DAN THEO TEN - INTERCHANGE SORT---");
            InterchangeSortDownTEN(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 6:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN GIAM DAN THEO MA SO - BUBBLE SORT---");
            BubbleSortUpMS(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 7:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN TANG DAN THEO MA SO - BUBBLE SORT---");
            BubbleSortDownMS(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 8:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN GIAM DAN THEO TEN - BUBBLE SORT---");
            BubbleSortDownTEN(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 9:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN TANG DAN THEO TEN - BUBBLE SORT---");
            BubbleSortUpTEN(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 10:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN TANG DAN THEO MA SO - SELECTION SORT---");
            SelectionSortUpMS(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 11:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN GIAM DAN THEO MA SO - SELECTION SORT---");
            SelectionSortDownMS(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 12:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN TANG DAN THEO TEN - SELECTION SORT---");
            SelectionSortUpTEN(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 13:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN GIAM DAN THEO TEN - SELECTION SORT---");
            SelectionSortDownTEN(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 14:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN TANG DAN THEO MA SO - INSERTION SORT---");
            InsertionSortUpMS(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 15:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN GIAM DAN THEO MA SO - INSERTION SORT---");
            InsertionSortDownMS(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 16:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN TANG DAN THEO TEN - INSERTION SORT---");
            InsertionSortUpTEN(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 17:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN GIAM DAN THEO TEN - INSERTION SORT---");
            InsertionSortDownTEN(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 18:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN TANG DAN THEO MA SO - SHELL SORT---");
            ShellSortUpMS(a, n, h, k);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 19:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN GIAM DAN THEO MA SO - SHELL SORT---");
            ShellSortDownMS(a, n, h, k);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 20:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN TANG DAN THEO TEN - SHELL SORT---");
            ShellSortUpTEN(a, n, h, k);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 21:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN GIAM DAN THEO TEN - SHELL SORT---");

            ShellSortDownTEN(a, n, h, k);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 22:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN TANG DAN THEO MA SO - QUICK SORT---");
            QuickSortUpMS(a, 0, n-1);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 23:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN GIAM DAN THEO MA SO - QUICK SORT---");
            QuickSortDownMS(a, 0, n - 1);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 24:
        system("cls");
            puts("---SX DANH SACH NHAN VIEN TANG DAN THEO TEN - QUICK SORT---");
            QuickSortUpTEN(a, 0, n - 1);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 25:
            system("cls");
            puts("---SX DANH SACH NHAN VIEN GIAM DAN THEO TEN - QUICK SORT---");
            QuickSortDownTEN(a, 0, n - 1);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;

    case 26:
            system("cls");
            puts("---SX DANH SACH NHAN VIEN TANG DAN THEO MA SO - MERGE SORT---");
            MergeSortUpMS(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 27:
            system("cls");
            puts("---SX DANH SACH NHAN VIEN GIAM DAN THEO MA SO - MERGE SORT---");
            MergeSortDownMS(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 28:
            system("cls");
            puts("---SX DANH SACH NHAN VIEN TANG DAN THEO TEN - MERGE SORT---");
            MergeSortUpTEN(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 29:
            system("cls");
            puts("---SX DANH SACH NHAN VIEN GIAM DAN THEO TEN - MERGE SORT---");
            MergeSortDownTEN(a, n);
            xuatnv(a, n);
            puts("\nNhan phim bat ki de quay lai MENU !");
            getch();    goto back;
    case 0:
        break;
       
    }
    getch();
}