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

推荐订阅源

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

博客园 - 玉米疯收

转载:算法方面的一些书籍和网上资源 [C语言]排序问题 - 玉米疯收 - 博客园 如何利用css使PNG图片透明 - 玉米疯收 - 博客园 So, you think you know JavaScript? (你认为你懂JS吗) 不用密码使用ssh管理远程linux服务器 [转]mysql性能的检查和调优方法 PHP 中巧用数组降低程序的时间复杂度 HTTP协议中的5类状态码 冬日随笔 牛年求牛。 统计字符串中单词个数的算法优化 shell练习:svndiff & change_ip MYSQL的慢查询分析 - 玉米疯收 csft安装过程中出错的问题及解决办法(目前仍然无法成功进行对中文的处理) - 玉米疯收 强烈鄙视“做成像……一样就可以了”这种需求被不负责任的提出 (转)关于程序员考研的研究 - 玉米疯收 搭建PHP的缓存服务Memcache Gentoo用上虚拟机中的战斗机KVM 国外的程序员也这样!
[C语言]排序问题--我的解答
玉米疯收 · 2010-03-02 · via 博客园 - 玉米疯收

#include <stdio.h>
#include
<stdlib.h>
#include
<string.h>#define MAX 100000
int file_name = 0 ;void merge(int nums[], int start, int new_mid, int end);
void qqsort(int a[],int low,int high);
int partions(int a[],int low,int high);
int segment(FILE *fp );int main()
{
FILE
*fp;
//FILE *fps, *fpa, *fpb, *fpc;
fp = fopen("num.txt", "r");
segment(fp);
fclose(fp);
//printf("segment done, total:%d\n", file_name );
//return 0;

int p = 0, i = 0;
char fn[3] = "";
char ch[20] = "";
int cache[file_name];
int cmax;
int t[file_name];
FILE
*fpp[file_name];
fp
= fopen("num_b.txt", "w+");
for(; p < file_name; p++)
{
sprintf(fn,
"%d", p);
fpp[p]
= fopen(fn , "r");
if((fgets(ch, 20, fpp[p])) != NULL)
cache[p]
= atoi(ch);
}

cmax

= 0;
while(1)
{
for(p = 0; p < file_name; p++)
{
if(cache[p] > cache[cmax])
{
cmax
= p;
}
}
//printf("\n%d\n",cache[cmax]);
//sprintf(fn, "%d", cmax);

if(cache[cmax] != -1)
{
fprintf( fp,
"%d\n", cache[cmax]);
t[cmax]
++;
if((fgets(ch, 15, fpp[cmax])) != NULL)
{
cache[cmax]
= atoi(ch);
}
else
{
cache[cmax]
= -1;
}
}
else
{
fclose(fp);
char num[3];
for(p = 0; p < file_name; p++)
{
sprintf(num,
"%d", p);
remove(num);
}
return 0;
}

}

return 0;
}
int partions(int a[],int low,int high)
{
int pivotkey=a[low];
int s;
s
=a[low];
while(low<high)
{
while(low<high && a[high]<=pivotkey)
--high;
a[low]
=a[high];
while(low<high && a[low]>=pivotkey)
++low;
a[high]
=a[low];
}
a[low]
=s;
return low;
}
void qqsort(int a[],int low,int high)
{
int pivottag;
if(low<high )
{
//递归调用
pivottag=partions(a,low,high);
qqsort(a,low,pivottag
-1);
qqsort(a,pivottag
+1,high);
}
}
int write_file(FILE *fp, int nums[])
{
qqsort(nums ,
0 , MAX-1);
int c =0;
while(1)
{
fprintf( fp,
"%d\n", nums[c]);
if (++c == MAX ) return 0;
}
}
int segment(FILE *fp )
{
char ch[20];
char num[3];
int nums[MAX];
int i = 0;
FILE
* fpr ;
while(fgets(ch,100, fp) != NULL)
{
if(i <= MAX){
nums[i]
= atoi(ch);
}
else{
sprintf(num,
"%d", file_name);
fpr
= fopen( num , "w+");
write_file(fpr, nums);
fclose(fpr);
file_name
++;
i
= 0;
nums[i]
= atoi(ch);
}

i

++;
}
sprintf(num,
"%d", file_name);
fpr
= fopen( num , "w+");
write_file(fpr, nums);
fclose(fpr);
file_name
++;
return 0;
}