EasyX 是针对 C/C++ 的图形库,可以帮助使用C/C++语言的程序员快速上手图形和游戏编程。
比如,可以用 VC + EasyX 很快的用几何图形画一个房子,或者一辆移动的小车,可以编写俄罗斯方块、贪吃蛇、黑白棋等小游戏,可以练习图形学的各种算法,等等。————百度百科
easyx的文档:https://docs.easyx.cn/en-us/intro
其实原理很简单,就是利用easyx的画圆功能,然后定位输出功能,然后加上清屏和延时函数,建议实现动画效果。
顺序表和单链表的结构体定义我就不赘述了。
因为整个代码冗长,我就不一一讲解了,我就写几个重要的函数,最后会附上源代码。
圆的定义:
typedef struct
{
int x;//横坐标
int y;//纵坐标
int r;//半径
int h[20];//记录数字
int hl;//数据位数
}Cir;//圆
矩形的定义:
typedef struct
{
int right;//右边框的横坐标
int top;//上边框的纵坐标
int left;//左边框的横坐标
int bottom;//下边框的纵坐标
int j[20];//记录数据
int jl; //记录数据位数
}Rec;//矩形
画圆函数:(还要在圆上打印数字,我只做了两位数)
void Circle(Cir c)
{
circle(c.x, c.y, c.r);
if(c.hl==1)
{
outtextxy(c.x - 3, c.y - 7, c.h[0]+48);
}
else
{
outtextxy(c.x - 7, c.y - 7, c.h[1]+48);
outtextxy(c.x , c.y - 7, c.h[0]+48);
}
}
画矩形函数:
void Rectangle(Rec r)
{
rectangle(r.right,r.top,r.left,r.bottom);
line(r.left+30,r.top,r.left+30,r.bottom);
if(r.jl==1)
{
outtextxy(r.right - 48, r.bottom - 17, r.j[0]+48);
}
else
{
outtextxy(r.right - 52, r.bottom - 17, r.j[1]+48);
outtextxy(r.right - 45, r.bottom - 17, r.j[0]+48);
}
}
顺序表插入移动函数:(核心是在不同坐标处画圆)
void InsertMove(Sqlist L,int i,int e)
{
initgraph(1000, 1000);
setlinecolor(WHITE);
int m;
Cir t;
t.x = 36;
t.y = 88;
t.r = 16;
t.hl = 0;
while(e)
{
t.h[t.hl++] = e%10;
e = e/10;
}
for(m=L.len-1; m>=i-1; m--)
{
Cir n;
int k;
int a;
int l = L.num[m];
n.y = 36;
n.r = 16;
n.hl = 0;
while(l)
{
n.h[n.hl++] = l%10;
l = l/10;
}
for (k=L.c[m].x; k<=L.c[m].x+52; k++)
{
for (a=0; a<L.len; a++)
{
if(a==m)
continue;
Circle(L.c[a]);
}
n.x = k;
Circle(t);
Circle(n);
Sleep(10);
cleardevice();
}
L.c[m].x += 52;
}
int a,k;
for (k=36; k<=52*(i-1) + 36; k++)
{
for (a=0; a<L.len; a++)
{
Circle(L.c[a]);
}
t.x = k;
Circle(t);
Sleep(10);
cleardevice();
}
for (k=88; k>=36; k--)
{
for (a=0; a<L.len; a++)
{
Circle(L.c[a]);
}
t.y = k;
Circle(t);
Sleep(10);
cleardevice();
}
for (a=0; a<L.len; a++)
{
Circle(L.c[a]);
}
Circle(t);
Sleep(5000);
closegraph();
}
下面附上源代码(可能有点长。。。)(技术挺臭的,没有简化代码,有兴趣可以简化一下。)
#include <graphics.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<windows.h>
#define MAXSIZE 100
typedef struct
{
int x;
int y;
int r;
int h[20];
int hl;
}Cir;//圆
typedef struct
{
int right;
int top;
int left;
int bottom;
int j[20];
int jl;
}Rec;//矩形
typedef struct
{
int num[MAXSIZE];
Cir c[MAXSIZE];
int len;
}Sqlist;
Sqlist L;
typedef struct Lnode
{
int x;
Rec r;
struct Lnode *next;
}LNode,*Linklist;
Linklist LL;
Sqlist Init(Sqlist L)
{
L.len = 0;
return L;
}
Linklist Init1(Linklist L)
{
L = (Linklist)malloc(sizeof(Linklist*));
if(!L)
{
printf("创建失败!\n");
return NULL;
}
L->next = NULL;
return L;
}
Sqlist Create(Sqlist L)
{
int l;
printf("要创建的顺序表的长度为:\n");
scanf_s("%d", &l);
L.len = l;
int i;
int n;
printf("请输入数据:\n");
for (i = 0; i < L.len; i++)
{
scanf_s("%d", &n);
L.num[i] = n;
L.c[i].x = 52*i + 36 ;
L.c[i].y = 36;
L.c[i].r = 16;
L.c[i].hl = 0;
while(n)
{
L.c[i].h[L.c[i].hl++] = n%10;
n = n/10;
}
}
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t按任意键继续...");
int x = _getch();
return L;
}
Linklist Create1(Linklist L)
{
L = Init1(L);
Linklist t = L;
int n;
int a;
printf("要创建的单链表的长度为:\n");
scanf_s("%d",&n);
printf("请输入数据:\n");
for (int i=0; i<n; i++)
{
scanf_s("%d",&a);
Linklist s;
s = (Linklist)malloc(sizeof(LNode));
s->x = a;
s->r.right = 120 * (i+1) + 80;
s->r.top = 20;
s->r.left = s->r.right - 60;
s->r.bottom = s->r.top + 20;
s->r.jl = 0;
while(a)
{
s->r.j[s->r.jl++] = a%10;
a = a/10;
}
t->next = s;
s->next = NULL;
t = s;
}
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t按任意键继续...");
int x = _getch();
return L;
}
void Circle(Cir c)
{
circle(c.x, c.y, c.r);
if(c.hl==1)
{
outtextxy(c.x - 3, c.y - 7, c.h[0]+48);
}
else
{
outtextxy(c.x - 7, c.y - 7, c.h[1]+48);
outtextxy(c.x , c.y - 7, c.h[0]+48);
}
}
void Rectangle(Rec r)
{
rectangle(r.right,r.top,r.left,r.bottom);
line(r.left+30,r.top,r.left+30,r.bottom);
if(r.jl==1)
{
outtextxy(r.right - 48, r.bottom - 17, r.j[0]+48);
}
else
{
outtextxy(r.right - 52, r.bottom - 17, r.j[1]+48);
outtextxy(r.right - 45, r.bottom - 17, r.j[0]+48);
}
}
void InsertMove(Sqlist L,int i,int e)
{
initgraph(1000, 1000);
setlinecolor(WHITE);
int m;
Cir t;
t.x = 36;
t.y = 88;
t.r = 16;
t.hl = 0;
while(e)
{
t.h[t.hl++] = e%10;
e = e/10;
}
for(m=L.len-1; m>=i-1; m--)
{
Cir n;
int k;
int a;
int l = L.num[m];
n.y = 36;
n.r = 16;
n.hl = 0;
while(l)
{
n.h[n.hl++] = l%10;
l = l/10;
}
for (k=L.c[m].x; k<=L.c[m].x+52; k++)
{
for (a=0; a<L.len; a++)
{
if(a==m)
continue;
Circle(L.c[a]);
}
n.x = k;
Circle(t);
Circle(n);
Sleep(10);
cleardevice();
}
L.c[m].x += 52;
}
int a,k;
for (k=36; k<=52*(i-1) + 36; k++)
{
for (a=0; a<L.len; a++)
{
Circle(L.c[a]);
}
t.x = k;
Circle(t);
Sleep(10);
cleardevice();
}
for (k=88; k>=36; k--)
{
for (a=0; a<L.len; a++)
{
Circle(L.c[a]);
}
t.y = k;
Circle(t);
Sleep(10);
cleardevice();
}
for (a=0; a<L.len; a++)
{
Circle(L.c[a]);
}
Circle(t);
Sleep(5000);
closegraph();
}
void InsertMove1(Linklist L,int s,int e)
{
initgraph(1500, 700);
setlinecolor(WHITE);
Rec t;
t.right = 80;
t.top = 70;
t.left = 20;
t.bottom = 90;
t.jl = 0;
while(e)
{
t.j[t.jl++] = e%10;
e = e/10;
}
int m,n;
for (m=80+120*(s-1),n = m+60;t.left<=m&&t.right<=n;t.left++,t.right++)
{
int i = 1;
Linklist p = L->next;
while(p)
{
rectangle(80,20,20,40);
line(50,20,50,40);
outtextxy(32,23,'L');
Rectangle(p->r);
line(120*(i-1)+65,30,120*(i-1)+135,30);
POINT pts[] = { {120*(i-1)+130, 25}, {120*(i-1)+130, 35}, {120*(i-1)+135, 30} };
polygon(pts, 3);
i++;
p = p->next;
}
Rectangle(t);
if(t.left!=m&&t.right!=n)
{
Sleep(10);
cleardevice();
}
}
Sleep(1000);
cleardevice();
int i = 1;
Linklist p = L->next;
while(p)
{
rectangle(80,20,20,40);
line(50,20,50,40);
outtextxy(32,23,'L');
Rectangle(p->r);
if(i!=s)
{
line(120*(i-1)+65,30,120*(i-1)+135,30);
POINT pts[] = { {120*(i-1)+130, 25}, {120*(i-1)+130, 35}, {120*(i-1)+135, 30} };
polygon(pts, 3);
}
i++;
p = p->next;
}
Rectangle(t);
Sleep(1000);
line(n-15,80,n+5,60);
POINT pts[] = { {n,60}, {n+5, 65}, {n+5,60} };
polygon(pts, 3);
Sleep(1000);
line(m-15,30,m+5,50);
POINT pts1[] = { {m,50}, {m+5, 45}, {m+5,50} };
polygon(pts1, 3);
Sleep(5000);
closegraph();
}
void DeleteMove(Sqlist L,int i)
{
initgraph(1000, 1000);
setlinecolor(WHITE);
int m;
int a;
for(m=L.c[i].y;L.c[i].y<=m+40;L.c[i].y++)
{
for (a=0; a<L.len; a++)
{
if(a==i)
continue;
Circle(L.c[a]);
}
Circle(L.c[i]);
Sleep(10);
cleardevice();
}
int b;
int k;
Cir n;
for (b=i+1; b<L.len ; b++)
{
for (k=L.c[b].x; k>=L.c[b].x-52; k--)
{
for (a=0; a<L.len; a++)
{
if(a==b)
continue;
Circle(L.c[a]);
}
n.x = k;
n.y = 36;
n.r = 16;
int s = L.num[b];
n.hl = 0;
while(s)
{
n.h[n.hl++] = s%10;
s = s/10;
}
Circle(n);
Sleep(10);
cleardevice();
}
L.c[b].x -= 52;
}
for (a=0; a<L.len; a++)
{
if(a==i)
continue;
Circle(L.c[a]);
}
Sleep(5000);
closegraph();
}
void DeleteMove1(Linklist L,int s,int l)
{
initgraph(1500, 700);
setlinecolor(WHITE);
int m,n;
Linklist q = L->next;
while(q)
{
if(q->x == l)
break;
q = q->next;
}
for(m=60,n=80;q->r.top<=m,q->r.bottom<=n;q->r.top++,q->r.bottom++)
{
int i = 1;
Linklist p = L->next;
while(p)
{
rectangle(80,20,20,40);
line(50,20,50,40);
outtextxy(32,23,'L');
Rectangle(p->r);
line(120*(i-1)+65,30,120*(i-1)+135,30);
POINT pts[] = { {120*(i-1)+130, 25}, {120*(i-1)+130, 35}, {120*(i-1)+135, 30} };
polygon(pts, 3);
i++;
p = p->next;
}
if(q->r.top!=m&&q->r.bottom!=n)
{
Sleep(10);
cleardevice();
}
}
Sleep(1000);
cleardevice();
int i = 1;
Linklist p = L->next;
while(p)
{
rectangle(80,20,20,40);
line(50,20,50,40);
outtextxy(32,23,'L');
Rectangle(p->r);
if(i!=s&&i!=(s+1))
{
line(120*(i-1)+65,30,120*(i-1)+135,30);
POINT pts[] = { {120*(i-1)+130, 25}, {120*(i-1)+130, 35}, {120*(i-1)+135, 30} };
polygon(pts, 3);
}
i++;
p = p->next;
}
Sleep(1000);
line(120*(s-1)+65,30,120*s+135,30);
POINT pts1[] = { {120*s+130, 25}, {120*s+130, 35}, {120*s+135, 30} };
polygon(pts1, 3);
Sleep(5000);
closegraph();
}
void SearchMove(Sqlist L,int i,int n)
{
initgraph(1000, 1000);
setlinecolor(WHITE);
Cir t;
t.x = 36;
t.y = 88;
t.r = 16;
t.hl = 0;
while(n)
{
t.h[t.hl++] = n%10;
n = n/10;
}
int a,k;
for (k=36; k<=52*i + 36;k++)
{
for (a=0; a<L.len; a++)
{
Circle(L.c[a]);
}
t.x = k;
Circle(t);
Sleep(10);
cleardevice();
}
for (a=0; a<L.len; a++)
{
Circle(L.c[a]);
}
Circle(t);
rectangle(L.c[i].x+26,10,L.c[i].x-26,114);
Sleep(5000);
closegraph();
}
void SearchMove1(Linklist L,int e)
{
initgraph(1500, 700);
setlinecolor(WHITE);
Linklist q = L->next;
while(q)
{
if(q->x == e)
break;
q = q->next;
}
Rec t;
t.right = 80;
t.top = 70;
t.left = 20;
t.bottom = 90;
t.jl = 0;
while(e)
{
t.j[t.jl++] = e%10;
e = e/10;
}
int m,n;
for (m=q->r.left,n=q->r.right;t.left<=m&&t.right<=n;t.left++,t.right++)
{
int i = 1;
Linklist p = L->next;
while(p)
{
rectangle(80,20,20,40);
line(50,20,50,40);
outtextxy(32,23,'L');
Rectangle(p->r);
line(120*(i-1)+65,30,120*(i-1)+135,30);
POINT pts[] = { {120*(i-1)+130, 25}, {120*(i-1)+130, 35}, {120*(i-1)+135, 30} };
polygon(pts, 3);
i++;
p = p->next;
}
Rectangle(t);
if(t.left!=m&&t.right!=n)
{
Sleep(10);
cleardevice();
}
}
Sleep(1000);
rectangle(q->r.right+10,10,q->r.left-10,100);
Sleep(5000);
closegraph();
}
void UpdateMove(Sqlist L,int i,int n)
{
initgraph(1000, 1000);
setlinecolor(WHITE);
Cir t;
t.x = 36;
t.y = 88;
t.r = 16;
t.hl = 0;
while(n)
{
t.h[t.hl++] = n%10;
n = n/10;
}
int a,k;
for (k=36; k<=52*i + 36;k++)
{
for (a=0; a<L.len; a++)
{
Circle(L.c[a]);
}
t.x = k;
Circle(t);
Sleep(10);
cleardevice();
}
for (k=88; k>=36;k--)
{
for (a=0; a<L.len; a++)
{
Circle(L.c[a]);
}
t.y = k;
Circle(t);
Sleep(10);
cleardevice();
}
for (a=0; a<L.len; a++)
{
if(a==i)
{
continue;
}
Circle(L.c[a]);
}
Circle(t);
Sleep(5000);
closegraph();
}
void UpdateMove1(Linklist L,int e,int l)
{
initgraph(1500, 700);
setlinecolor(WHITE);
Linklist q = L->next;
while(q)
{
if(q->x == l)
break;
q = q->next;
}
Rec t;
t.right = 80;
t.top = 70;
t.left = 20;
t.bottom = 90;
t.jl = 0;
while(e)
{
t.j[t.jl++] = e%10;
e = e/10;
}
int m,n;
for (m=q->r.left,n=q->r.right;t.left<=m&&t.right<=n;t.left++,t.right++)
{
int i = 1;
Linklist p = L->next;
while(p)
{
rectangle(80,20,20,40);
line(50,20,50,40);
outtextxy(32,23,'L');
Rectangle(p->r);
line(120*(i-1)+65,30,120*(i-1)+135,30);
POINT pts[] = { {120*(i-1)+130, 25}, {120*(i-1)+130, 35}, {120*(i-1)+135, 30} };
polygon(pts, 3);
i++;
p = p->next;
}
Rectangle(t);
if(t.left!=m&&t.right!=n)
{
Sleep(10);
cleardevice();
}
}
Sleep(1000);
for (m=q->r.top,n=q->r.bottom;t.top>=m&&t.bottom>=n;t.top--,t.bottom--)
{
int i = 1;
Linklist p = L->next;
while(p)
{
rectangle(80,20,20,40);
line(50,20,50,40);
outtextxy(32,23,'L');
Rectangle(p->r);
line(120*(i-1)+65,30,120*(i-1)+135,30);
POINT pts[] = { {120*(i-1)+130, 25}, {120*(i-1)+130, 35}, {120*(i-1)+135, 30} };
polygon(pts, 3);
i++;
p = p->next;
}
Rectangle(t);
if(t.top!=m&&t.bottom!=n)
{
Sleep(10);
cleardevice();
}
}
Sleep(5000);
closegraph();
}
Sqlist Insert(Sqlist L)
{
int i;
int n;
printf("请输入要插入的位置:\n");
scanf_s("%d", &i);
printf("请输入要插入的数据:\n");
scanf_s("%d", &n);
InsertMove(L,i,n);
int k;
for(k = L.len-1; k>=i-1; k--)
{
L.c[k].x += 52;
}
for (k = L.len; k >= i; k--)
{
L.num[k] = L.num[k - 1];
L.c[k] = L.c[k-1];
}
L.num[i - 1] = n;
L.c[i-1].x = 52*(i-1) + 36;
L.c[i-1].y = 36;
L.c[i-1].r = 16;
L.c[i-1].hl = 0;
while(n)
{
L.c[i-1].h[L.c[i-1].hl++] = n%10;
n = n/10;
}
L.len++;
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t按任意键继续...");
int x = _getch();
return L;
}
Linklist Insert1(Linklist L)
{
int n;
printf("请输入要插入的位置:\n");
scanf_s("%d", &n);
Linklist p;
p = L->next;
int i = 1;
while(p&&i<n-1)
{
p = p->next;
i++;
}
if(!p)
{
printf("插入位置有误!\n");
return 0;
}
Linklist s;
s = (Linklist)malloc(sizeof(LNode));
printf("请输入要插入数据:\n");
scanf_s("%d",&s->x);
InsertMove1(L,n,s->x);
s->next = p->next;
p->next = s;
p = s->next;
while(p)
{
p->r.left += 120;
p->r.right += 120;
p=p->next;
}
s->r.right = 80 + 120*n;
s->r.left = 20+120*n;
s->r.top = 20;
s->r.bottom = 40;
s->r.jl = 0;
int l = s->x;
while(l)
{
s->r.j[s->r.jl++] = l%10;
l = l/10;
}
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t按任意键继续...");
int x = _getch();
return L;
}
Sqlist Delete(Sqlist L)
{
int n;
printf("请输入要删除的数据:\n");
scanf_s("%d", &n);
int k;
for (k=0; k<L.len; k++)
{
if(L.num[k] == n)
break;
}
DeleteMove(L,k);
int i;
for(i = k+1; i<L.len; i++)
{
L.c[i].x -= 52;
}
for(i=k; i<L.len-1; i++)
{
L.num[i] = L.num[i+1];
L.c[i] = L.c[i+1];
}
L.len--;
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t按任意键继续...");
int x = _getch();
return L;
}
Linklist Delete1(Linklist L)
{
int n;
printf("请输入要删除的数据:\n");
scanf_s("%d", &n);
int k = 1;
Linklist s = L->next;
while(s)
{
if(s->x == n)
break;
k++;
s = s->next;
}
DeleteMove1(L,k,n);
Linklist p = L;
while(p->next&&p->next->x!=n)
{
p = p->next;
}
if(!p->next)
{
printf("无此数据,无法删除\n");
return 0;
}
Linklist q = p->next;
p->next = q->next;
free(q);
p = p->next;
while(p)
{
p->r.left -= 120;
p->r.right -= 120;
p=p->next;
}
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t按任意键继续...");
int x = _getch();
return L;
}
void Search(Sqlist L)
{
int n;
int k;
printf("请输入要查找的数据:\n");
scanf_s("%d", &n);
for (k=0; k<L.len; k++)
{
if(L.num[k] == n)
break;
}
SearchMove(L,k,n);
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t按任意键继续...");
int x = _getch();
}
void Search1(Linklist L)
{
int a = 1;
int n;
printf("你要查找的数据是:\n");
scanf_s("%d",&n);
Linklist p = L->next;
while(p&&p->x!=n)
{
p = p->next;
a++;
}
if(!p)
{
printf("无此数据\n");
}
SearchMove1(L,n);
printf("有此数据,在第%d位\n",a);
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t按任意键继续...");
int x = _getch();
}
void Update(Sqlist *L)
{
int n;
printf("请输入要更新的数据:\n");
scanf_s("%d", &n);
int m;
printf("要将其更新为:\n");
scanf_s("%d", &m);
int k;
for (k=0; k<L->len; k++)
{
if(L->num[k] == n)
break;
}
UpdateMove(*L,k,m);
L->num[k] = m;
L->c[k].hl = 0;
while(m)
{
L->c[k].h[L->c[k].hl++] = m%10;
m = m/10;
}
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t按任意键继续...");
int x = _getch();
}
void Update1(Linklist *L)
{
int n;
printf("你要更新的数据是:\n");
scanf_s("%d",&n);
Linklist p = (*L)->next;
while(p&&p->x!=n)
{
p = p->next;
}
if(!p)
{
printf("无此数据\n");
}
int m;
printf("要将其更新为:\n");
scanf_s("%d", &m);
UpdateMove1(*L,m,n);
p->x = m;
p->r.jl = 0;
while(m)
{
p->r.j[p->r.jl++] = m % 10;
m = m/10;
}
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t按任意键继续...");
int x = _getch();
}
void Print(Sqlist L)
{
int i;
for (i = 0; i < L.len; i++)
{
printf("%d ", L.num[i]);
}
printf("\n");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t按任意键继续...");
int x = _getch();
}
void Print1(Linklist L)
{
Linklist p = L->next;
while(p)
{
printf("%d ",p->x);
p = p->next;
}
printf("\n");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t按任意键继续...");
int x = _getch();
}
void Show1(Linklist L)//用图形展示当前单链表
{
initgraph(1500, 700);
setlinecolor(WHITE);
int i = 1;
Linklist p = L->next;
while(p)
{
rectangle(80,20,20,40);
line(50,20,50,40);
outtextxy(32,23,'L');
Rectangle(p->r);
line(120*(i-1)+65,30,120*(i-1)+135,30);
POINT pts[] = { {120*(i-1)+130, 25}, {120*(i-1)+130, 35}, {120*(i-1)+135, 30} };
polygon(pts, 3);
i++;
p = p->next;
}
Sleep(5000);
closegraph();
}
void Show(Sqlist L)//用图形展示当前顺序表
{
initgraph(1000, 1000);
setlinecolor(WHITE);
int i;
for (i=0; i<L.len; i++)
{
Circle(L.c[i]);
}
Sleep(5000);
closegraph();
}
void Menu()
{
printf("------------------------------------------------------------------------------------------------------------------------\n");
printf("\n\t\t\t***************欢迎来到线性表基本操作动画演示***************\n\n");
printf("\n\t\t\t\t\t按数字1键创建线性表\n\n");
printf("\n\t\t\t\t\t按数字2键对线性表插入数据\n\n");
printf("\n\t\t\t\t\t按数字3键对线性表删除数据\n\n");
printf("\n\t\t\t\t\t按数字4键查找线性表数据\n\n");
printf("\n\t\t\t\t\t按数字5键更新线性表数据\n\n");
printf("\n\t\t\t\t\t按数字6键打印当前线性表\n\n");
printf("\n\t\t\t\t\t按数字7键用图形展示当前线性表(5秒)\n\n");
printf("\n\t\t\t\t\t按数字8键结束程序\n\n");
printf("------------------------------------------------------------------------------------------------------------------------\n");
}
void Menu1()
{
printf("------------------------------------------------------------------------------------------------------------------------\n");
printf("\n\t\t\t***************欢迎来到单链表基本操作动画演示***************\n\n");
printf("\n\t\t\t\t\t按数字1键创建单链表\n\n");
printf("\n\t\t\t\t\t按数字2键单链表表插入数据\n\n");
printf("\n\t\t\t\t\t按数字3键单链表表删除数据\n\n");
printf("\n\t\t\t\t\t按数字4键查找单链表数据\n\n");
printf("\n\t\t\t\t\t按数字5键更新单链表数据\n\n");
printf("\n\t\t\t\t\t按数字6键打印当前单链表\n\n");
printf("\n\t\t\t\t\t按数字7键用图形展示当前单链表(5秒)\n\n");
printf("\n\t\t\t\t\t按数字8键结束程序\n\n");
printf("------------------------------------------------------------------------------------------------------------------------\n");
}
void Operate()
{
int n = _getch();
switch(n)
{
case 49 :system("cls");L = Create(L);break;
case 50:system("cls");L = Insert(L);break;
case 51:system("cls"); L = Delete(L);break;
case 52:system("cls"); Search(L);break;
case 53:system("cls"); Update(&L);break;
case 54:system("cls");Print(L);break;
case 55:system("cls");Show(L);break;
case 56:exit(0);
}
}
void Operate1()
{
int n = _getch();
switch(n)
{
case 49 :system("cls");LL = Create1(LL);break;
case 50:system("cls");LL = Insert1(LL);break;
case 51:system("cls"); LL = Delete1(LL);break;
case 52:system("cls"); Search1(LL);break;
case 53:system("cls"); Update1(&LL);break;
case 54:system("cls");Print1(LL);break;
case 55:system("cls");Show1(LL);break;
case 56:exit(0);
}
}
void menu()
{
printf("------------------------------------------------------------------------------------------------------------------------\n");
printf("\n\t\t\t\t***************欢迎来到动画演示***************\n\n");
printf("\n\t\t\t\t\t按数字1键进入线性表基本操作动画演示\n\n");
printf("\n\t\t\t\t\t按数字2键进入单链表基本操作动画演示\n\n");
printf("\n\t\t\t\t\t按数字0键结束程序\n\n");
printf("------------------------------------------------------------------------------------------------------------------------\n");
int n = _getch();
switch(n)
{
case 49 :
while(1)
{
system("cls");
Menu();
Operate();
}break;
case 50:while(1)
{
system("cls");
Menu1();
Operate1();
}break;break;
case 48:exit(0);
}
}
int main()
{
menu();
return 0;
}