依睛(IT blog) 我回来了,PHP<-->C/C++ LINUX

笨鸟

统计

积分与排名

友情连接

最新评论

冒泡排序法

冒泡排序法
动态文件
#include <stdio.h>
#include <string.h>
#define True 1
#define False 0    
#define ARR_EXPORT  __declspec(dllexport)

/*    int ARR_EXPORT arrg(int a[len]) 不可以, 因在定义一个数组必须指定长度 */
/*
int ARR_EXPORT arrg(int a[], int len)
{

 int i=0,temp;
 int j;
 int ok=True;
 int count = len;

 for(i=0;i<count-1;i++) 
 {    
  for(j=count-1;j>=i;j--)
  {
   if(a[j]>a[j+1])
   {
    ok=False; temp=a[j];
    a[j]=a[j+1]; a[j+1]=temp;
   }
  }
  if(ok==True) 
    break;
 }
 return 0;
}
*/

int ARR_EXPORT arrg(int a[], int len)
{
    int temp,h,j,k;
 k=len;
 for(h=0;h<k-1;h++)
 {
              
  for(j=k-1;j>h;j--)
         if(a[j]<a[j-1])
   {
         temp=a[j];
               a[j]=a[j-1];
         a[j-1]=temp;
   }
 }

 return  0;
}


======================================

主文件
#include<stdio.h>
#define ARR_IMPORT __declspec(dllimport)

#pragma comment(lib, "arr_dll.lib")
extern int ARR_IMPORT arrg(int a[], int len);

int main()
{
 long int a[]={19, 18,88, 33, 17, 16, 15, 14, 13, 12, 11, 10, 8, 9, 7, 6, 5, 4, 3, 2, 1};
 int  i;
 int  len = (sizeof(a)/4);

 arrg(a, len);
 for(i=0; i<len; i++)
 {
  printf("%d  ", a[i]);
 }

 printf("\n");
// printf("size = %d\n", len);
 return 0;
}

posted on 2008-01-21 21:08 向左向右走 阅读(191) 评论(0)  编辑 收藏 引用 所属分类: C/C++学习资料库

只有注册用户登录后才能发表评论。