惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
The GitHub Blog
The GitHub Blog
C
Check Point Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
F
Full Disclosure
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
V
Vulnerabilities – Threatpost
K
Kaspersky official blog
博客园 - 司徒正美
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
云风的 BLOG
云风的 BLOG
Cisco Talos Blog
Cisco Talos Blog
Know Your Adversary
Know Your Adversary
雷峰网
雷峰网
V
V2EX - 技术
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Spread Privacy
Spread Privacy
罗磊的独立博客
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
SecWiki News
SecWiki News
Schneier on Security
Schneier on Security
O
OpenAI News
Jina AI
Jina AI
PCI Perspectives
PCI Perspectives
Cyberwarzone
Cyberwarzone
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
I
InfoQ
D
Docker
P
Palo Alto Networks Blog
Recorded Future
Recorded Future
M
MIT News - Artificial intelligence
博客园 - Franky
B
Blog
Scott Helme
Scott Helme
博客园 - 叶小钗
D
DataBreaches.Net

博客园 - lexus

选型思考 浙江省高等学校教师教育理论培训上机考试小程序设计架构 flutter RN taro选型思考 antv g6 IT职业后半段发展问题 培训活动 敏捷 咨询师 火星人陈勇博客牛人 fpa 功能点分析法 cto职责 博文阅读密码验证 - 博客园 zz 百度效率云 zz 产品研发体系中的需求承接与输出 - 尘世中 - 博客园 ESAPI学习笔记 - Fish_Ou - 博客园 - lexus 西安律师起诉酷骑单车 要求"退一赔三"_网易新闻 高校教师兼职改革要从“管好领导”做起-新华网 - lexus 首席技术官应该考虑的网络安全问题 IT大咖说 - 大咖干货,不再错过 xx
指针 冒泡排序法
lexus · 2018-03-21 · via 博客园 - lexus

指针 冒泡排序法

#include <stdio.h>
void swap(int *a, int *b);
void sort(int *a, int n);
void show(int *a, int n);

int main()
{
    int a[] = {4,7,3,1,4,2};
    int n = sizeof(a)/sizeof(int);
    printf("%ld\n",sizeof(int));
    sort(a , n);
    show(a , n);
    printf("\n");

    int z[] = {4,1};
    sort(z,2);
    show(z,2);
}

void swap(int *a, int *b)
{
        int tmp = *a;
        *a = *b;
        *b = tmp;
}

void sort(int *a, int n)
{
    int *p1,*p2,j;
    for(p1 = a , p2 = a+1 , j = 1;  p2 < a + n; p1++,p2++,j++)
    {
        for ( int i = 0; i < n - j; i++)
        {
            if (*p1 > *(p2+i))
            {
                //printf("-->%d,%d\n",*p1,*(p2+i));
                swap(p1,p2+i);
                //show(a,n);
            }
        }    
    }
}

void show(int *a, int n)
{
    for(int i = 0; i < n; i++)
    {
        printf("%d\t",a[i]);
    }
    printf("\n");
}

posted on 2018-03-21 15:17  lexus  阅读(966)  评论()    收藏  举报