Exemple #1
0
int main(void){

	int my_array[10] = {0, 17, -41, 2, 93, 71, -104, 91, 1, 42};
	int largest_bucket = get_imax(my_array, 10);

	printf("The largest value is: %d, in bucket %d\n", my_array[largest_bucket], largest_bucket);

	sel_sort(my_array, 10);

	for(int i = 0; i < 10; i++){
		printf("Sorted array: %d, %d\n", i, my_array[i]);
	}


	return 0;
}
static int get_lsys_name(PGENSEL gs)         /* get the Lsystem formula name */
{
   int numformulas, i;
   FILE *File;
   char buf[201], tempstring[201];

   for (i = 0; i < MAX_SEL; i++) {
      gs->szNames[i][0] = 0;
      }

   _fstrcpy(tempstring, npTempParms.szLSysFileName);
   if ((File = fopen(tempstring, "rt")) == NULL) {
      sprintf(buf,"I Can't find %s", tempstring);
      stopmsg(1,buf);
      gs->szSelected[0] = 0;
      return(-1);
      }

   numformulas = 0;
   while (1) {
      int c;
      gs->szNames[numformulas][0] = 0;
      if (fscanf(File, " %F20[^ \n\t({]", gs->szNames[numformulas]) == EOF)
         break;
      while(c = getc(File)) {
         if(c == EOF || c == '{' || c == '\n')
            break;
         }
      if(c == EOF)
         break;
      else if(c != '\n') {
skipcomments:
         if(fscanf(File, "%200[^}]", buf) == EOF) break;
         if (getc(File) != '}') goto skipcomments;
         if (_fstricmp(gs->szNames[numformulas],"") != 0 &&
             _fstricmp(gs->szNames[numformulas],"comment") != 0)
                 if (++numformulas >= MAX_SEL) break;
         }
      }
   fclose(File);

   gs->sCountNames = numformulas;
   /* now sort the names */
   sel_sort(gs);
   return(0);
}
static int get_formula_names(PGENSEL gs)  /* get the fractal formula names */
{
   int numformulas, i;
   FILE *File;
   char msg[81], tempstring[201];

   gs->szSelected[0] = 0;             /* start by declaring failure */
   for (i = 0; i < MAX_SEL; i++) {
      gs->szNames[i][0] = 0;
      }

   _fstrcpy(tempstring, npTempParms.szFormFileName);
   if((File = fopen(tempstring, "rt")) == NULL) {
      sprintf(msg,"I Can't find %s", tempstring);
      stopmsg(1,msg);
      return(-1);
   }

   numformulas = 0;
   while(fscanf(File, " %F20[^ \n\t({]", gs->szNames[numformulas]) != EOF) {
      int c;

      while(c = getc(File)) {
         if(c == EOF || c == '{' || c == '\n')
            break;
      }
      if(c == EOF)
         break;
      else if(c != '\n'){
         numformulas++;
         if (numformulas >= MAX_SEL-1) break;
skipcomments:
         if(fscanf(File, "%200[^}]", tempstring) == EOF) break;
         if (getc(File) != '}') goto skipcomments;
         if (_fstricmp(gs->szNames[numformulas-1],"") == 0 ||
             _fstricmp(gs->szNames[numformulas-1],"comment") == 0)
                 numformulas--;
      }
   }
   fclose(File);

   gs->sCountNames = numformulas;
   /* now sort the names */
   sel_sort(gs);
   return(0);
}
Exemple #4
0
int main()
{
	int n;
	
	printf("Enter the number of elements\n");	
	scanf("%d", &n);
	
	int A[n], i;
	
	printf("Enter the elements\n");
	
	for(i = 0; i < n; i++)
		scanf("%d", &A[i]);
	
	sel_sort(A, n);
	printf("Sorted Array after applying Selection Sort \n");

	for(i = 0; i < n; i++)
		printf("%d ", A[i]);

	
	printf("\n");
	return 0; 
}