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

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

博客园 - 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)  评论()    收藏  举报