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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

博客园 - lexus

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