25 int length,count,result=0;
30 str1=malloc((length+1)*
sizeof(
char));
36 for(count=0;result>=0&&(tmp=getchar())!=
'\n';count++)
41 str2=realloc(str1,length+1);
65 int length,count,result=0;
70 str1=malloc((length+1)*
sizeof(
char));
76 for(count=0;result>=0&&(tmp=getchar())!=EOF;count++)
81 str2=realloc(str1,length+1);
105 str[dim-1]=str[dim-2]=1;
106 ret=fgets(str,dim,stdin);
107 if(ret==NULL||(str[dim-1]==
'\0'&&str[dim-2]!=
'\n'))
109 while(getchar()!=
'\n');
114 length=strlen(str)-1;
124 static time_t seed = 0;
126 if(max<min) result=0;
132 srand((
unsigned)seed);
134 result=min+rand()%(max-min+1);
155 int merge(
void* vals[],
int begin,
int middle,
int end,
156 int(*comp)(
void*,
void*))
159 int size=end-begin+1;
160 int sizel=middle-begin;
161 void** copy=malloc(size*
sizeof(
void*));
165 for(i=0,k=begin;i<size;i++,k++)
169 for(i=0,j=sizel,k=begin;k<=end;k++)
171 if(j>=size||(i<sizel&&((*comp)(copy[i],copy[j])<0)))
188 int mergeSort(
void* vals[],
int begin,
int end,
int(*comp)(
void*,
void*))
196 result+=
merge(vals,begin,m+1,end,*comp);
int rgets(char **str)
Reads a line from the stdin.
int mergeSort(void *vals[], int begin, int end, int(*comp)(void *, void *))
Orders an array into ascending order, based on a given comparison function.
int rgetsEOF(char **str)
Reads a text from the stdin.
int merge(void *vals[], int begin, int middle, int end, int(*comp)(void *, void *))
Merges two ordered parts of an array of pointers, based on a given comparison function.
int rngets(char *str, int dim)
Reads a line from the stdin.
Implementation of some utility functions.
#define BUFSIZE
Size of the initial buffer to be used in functions rgets and rgetsEOF.
int getRandom(int min, int max)
Generates a random number in a given interval.