OpenCores
URL https://opencores.org/ocsvn/mips789/mips789/trunk

Subversion Repositories mips789

[/] [mips789/] [branches/] [avendor/] [bench/] [sort/] [sort.c] - Blame information for rev 53

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 mcupro
/******************************************************************
2
 *                                                                *
3
 *    Author: Liwei                                               *
4
 *                                                                *
5
 *    This file is part of the "mips789" project.                 *
6
 *    Downloaded from:                                            *
7
 *    http://www.opencores.org/pdownloads.cgi/list/mips789        *
8
 *                                                                *
9
 *    If you encountered any problem, please contact me via       *
10
 *    Email:mcupro@opencores.org  or mcupro@163.com               *
11
 *                                                                *
12
 ******************************************************************/
13
 
14
#include "..\..\clib\dvc_lib.h"
15
#include "..\..\clib\stringlib.h"
16
 
17
#define SORT_U16
18
 
19
 
20
#ifdef SORT_U8
21
#define DATA_TYPE   unsigned char
22
#define DATA_MAX 0xff
23
#else
24
#ifdef SORT_U16
25
#define DATA_TYPE  unsigned  short
26
#define DATA_MAX 0xffff
27
#else
28
#define DATA_TYPE   unsigned int
29
#define DATA_MAX 0xffffffff
30
#endif
31
#endif
32
void sort(DATA_TYPE*a,int num)
33
{
34
    int i,j ;
35
 
36
    DATA_TYPE tmp ;
37
 
38
    for(i=0;i<num;i++)
39
    {
40
        for(j=i+1;j<num;j++)
41
        {
42
            if(a[i]<a[j])
43
            {
44
                tmp=a[i];
45
                a[i]=a[j];
46
                a[j]=tmp ;
47
            }
48
        }
49
    }
50
}
51
 
52
DATA_TYPE array[16]={123,234,122,111,222,122,332,111,11,99,11,12,43,23,43,45};
53
 
54
 
55 35 mcupro
 
56 26 mcupro
char str[100];
57
void main2()
58
{
59
    int i ;
60
//initial_array(array,16);
61
    for(;;)
62
    {
63
 
64
        sort(array,16);
65
        for(i=0;i<16;++i)
66
        {
67
            sprintf(str,"  %x",array[i]);
68
            uart0_putstr(str);
69
        }
70
        uart0_putstr(" \n");
71
    }
72
}
73
 
74
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.