資源簡介
內部排序的程序很簡單 你可能也見過 但這個程序是把內部排序的程序跟一個小游戲結合起來的 界面也挺好的 自己結合一些小程序做的 基本上也沒什么難點 主要是算法呵呵

代碼片段和文件信息
#include?
#include?
#include?“stdlib.h“
#include?“stdio.h“
#include?“dos.h“
#include?“bios.h“
#include?“graphics.h“
#include?“math.h“
#include?“time.h“
#include?“ctype.h“
#define?ESC?0x11b
#define?ENTER?0x1c0d
#define?UP?0x4800
#define?DOWN?0x5000
#define?LEFT?0x4b00
#define?RIGHT?0x4d00
#define?MAXSIZE?100
#define?DELAY?for(?count=0;count<=interval;count++){delay(count);}
#define?INTERVAL?300
#define?N?200
/**********定義排序全局變量************/
typedef?int?Keytype;
typedef?struct?rec{
????Keytype?key;
}redtype;
typedef?struct{
????redtype?r[MAXSIZE+1];
????long?length;
}Sqlist;
int?count;
int?intetval=INTERVAL?;
int?key=0;
int?mode=1;
int?ikey;
?
/**********定義貪吃蛇全局變量************/
int?score=0;/*得分*/?
int?gamespeed=50000;/*游戲速度自己調整*/?
struct?Food?
{?
???int?x;/*食物的橫坐標*/?
???int?y;/*食物的縱坐標*/?
???int?yes;/*判斷是否要出現食物的變量*/?
}food;/*食物的結構體*/?
struct?Snake?
{?
???int?x[N];?
???int?y[N];?
???int?node;/*蛇的節數*/?
???int?direction;/*蛇移動方向*/?
???int?life;/*?蛇的生命0活著1死亡*/?
}snake;?
/**********定義排序函數************/
bubblesort(struct?rec?r[]int?n)??/*冒泡排序*/
{
?int?ij;
?struct?rec?w;
?unsigned?long?int?compare=0move=0;
?for(i=1;i<=n-1;i++)
?for(j=n-1;j>=i+1;j--)
?{
?if(r[j].key ??{
????w=r[j];
????r[j]=r[j-1];
????r[j-1]=w;
????move=move+3;
??}
?compare++;
?}
?printf(“bubblesort?compare=?%ldmove=?%ld\n“comparemove);
}
selectsort(struct?rec?r[]int?n)??/*簡單選擇*/
{
??unsigned?long?int?compare=0move=0;
??int?ijk;
??struct?rec?w;
??for(i=1;i ???{?k=i;
?????for(j=i+1;j ?????????{?if(r[j].key>r[k].key)?
??????????????{
????????????????compare++;?
??????????????}
???????????else{w=r[j];
????????????????r[j]=r[k];
????????????????r[k]=w;
????????????????move=move+3;
???????????????}
?????????}
???}
??printf(“selectsort?compare=?%ldmove=?%ld\n“comparemove);
}
int?partition(struct?rec?r[]int?lowint?high)/*快速排序*/
{
??int?p;
??r[0]=r[low];?
??p=r[low].key;?
??while(low ????while(low=p)?--high;
????r[low]=r[high];
????while(low ????r[high]=r[low];
???}
??r[low]=r[0];
??return?low;
}
quicksort(struct?rec?r[]int?lowint?high)
{
???int?j;
???if(low ???????j=partition(rlowhigh);
???????quicksort(rlowj-1);
???????quicksort(rj+1high);
????????}
}
insertsort(struct?rec?r[]int?n)/*直接插入*/
{
int?ij;
unsigned?long?int?compare=0move=0;
for(i=2;i<=n;i++)
?{?compare++;
???r[0]=r[i];
???move++;
???j=i-1;
??while(r[0].key ???{?r[j+1]=r[j];
?????j--;
?????move++;
?????++compare;
???}
??r[j+1]=r[0];
??move++;
?}
printf(“insertsort?compare=?%ldmove=?%ld\n“comparemove);
}
sift(struct?rec?r[]int?lint?m)?/*堆排序*/
{
int?ij;
struct?rec?w;
i=l;?j=2*i;
w=r[i];
while(j<=m)
{
if(j {?j++;
}
if(w.key {
?r[i]=r[j];
?i=j;
?j=2*i;
}
else?j=m+1;
}
r[i]=w;
}
h
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????17349??2009-12-17?16:31??paixu.c
-----------?---------??----------?-----??----
????????????????17349????????????????????1
評論
共有 條評論