#include "bubblesort.h"
#include "LCD12864.h"
#include "delay.h"
#define uchar unsigned char
extern uchar xdata window[16];
extern uchar xdata Line_1[16] ;
extern uchar xdata Line_2[16] ;
extern uchar xdata Line_3[16] ;
unsigned int bubblesort(table *tab)
{
uchar i,j,done;
i=0;
done=1;
while(i<=tab->length&&done) //最多进行tab->length次冒泡,没发生交换结束
{
done = 0;
for(j=1;j
length-i;j++) //将R[0]作为临时交换空间
if(tab->R[j+1].key > tab->R[j].key)
{
tab->R[0] = tab->R[j];
tab->R[j] = tab->R[j+1];
tab->R[j+1] = tab->R[0];
done = 1;
}
i++;
}
return tab->R[1].key*1000 + tab->R[1].value;
}
void insert(table *tab,keytype k,Vtype v)
{
uchar pos=MAXSIZE; //从最末尾插入值
tab->R[pos].key = k;
tab->R[pos].value = v;
tab->length = pos;
}
void main()
{
unsigned int Buffer[8];
unsigned char a;
table *pTab,tab;
pTab = &tab;
insert(pTab,1,1);
bubblesort(pTab);
insert(pTab,2,234);
bubblesort(pTab);
insert(pTab,3,234);
bubblesort(pTab);
insert(pTab,3,235);
bubblesort(pTab);
Buffer[0] = pTab->R[1].key;
Buffer[1] = pTab->R[1].value;
Buffer[2] = pTab->R[2].key;
Buffer[3] = pTab->R[2].value;
Buffer[4] = pTab->R[3].key;
Buffer[5] = pTab->R[3].value;
Buffer[6] = pTab->R[4].key;
Buffer[7] = pTab->R[4].value;
Line_2[3] = Buffer[0] + 48;
Line_2[5] = Buffer[2] + 48;
LCD12864_init_char();
while(1)
{
LCD12864_Display_char(1,0,Line_2);
}
}
结构体是这样定义的
#define MAXSIZE 30
typedef unsigned char keytype;typedef unsigned int Vtype;
typedef struct{ keytype key; //排序码 Vtype value; //对应值}xdata recordtype;
typedef struct{ recordtype R[MAXSIZE+1]; unsigned int length;}xdata table;
软件上仿真看,数据是对的,可是用12864显示值不对。不知道哪里出了错,希望帮忙找下问题,不胜感激。