📄 86.c
字号:
#include <stdio.h>#include <string.h>#include <stdlib.h>#define LINES 10void fastsort(char *pl[],int n){ int m=1,lb[20],ub[20],low,high,i,j; char *t; lb[m]=0;ub[m]=n-1; while(m){ low=lb[m];high=ub[m];m--; while(low<high){ i=low;j=high;t=pl[i]; while(i!=j){ while(strcmp(t,pl[j])<=0&&i!=j) j--; if(i!=j){ pl[i]=pl[j],i++; while(strcmp(t,pl[i])>=0&&i!=j) i++; if(i!=j)pl[j]=pl[i]; else pl[i]=t; } else pl[j]=t; }m++; if(i-low<=high-i){ ub[m]=high,lb[m]=i+1; high=i-1; } else{ ub[m]=i-1; lb[m]=low; low=i+1; } } }}readln(char *pl[],int maxl)//read filename and return total of lines{ int nl=0,i; char *p,s[80]; while(gets(s)!=NULL) if(nl>=maxl) return -1; else if((p=(char*)malloc(strlen(s)+1))==NULL) return -1; else{ strcpy(p,s); pl[nl++]=p; } return nl;}void writeln(char *pl[],int nl){ while(--nl>=0) printf("%s\n",*pl++);}void main(void){ char *pl[LINES],*s; int nl,sf,sj=0; printf("input the strings with F6 end\n"); if((nl=readln(pl,LINES))>=0){ fastsort(pl,nl); writeln(pl,nl); } else printf("lines is too many");}/*main(int argc,char *argv[]){ char *pl[LINES],*s; int nl,sf,sj=0; while(--argc>0){ s=*++argv; if(s[0]=='D'||s[0]=='d') sf=-1; else for(s=*argv;*s!='\0';s++) sj=10*sj+*s-48;//ASCII string to decimal } if((nl=readln(pl,LINES))>=0){ writeln(pl,nl); fastsort(pl,nl,sf,sj); writeln(pl,nl); } else printf("lines is too many");} */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -