Beispiel #1
0
int main(){
	srand(time(NULL)); //Damit rand() nicht immer gleiche Folgen ausgibt
	clock_t begin, end;
	int size;
	
	//Aufgabe 3b)
	//Sortieralgorithmen bereits nach ihrer Laufzeit sortiert.
	printf("Welche Laenge(int) soll das Array haben?\n>");
	scanf("%d", &size);
	printf("Eingegebene Arraylaenge: %d\nAuflistung der Laufzeiten:\n", size);
	
	double* arr = malloc(size * sizeof(double));
	double* arrCopy = malloc(size * sizeof(double));
	for(int i = 0; i < size; i++){
		arr[i] = randBet(-1000, 1000);
		arrCopy[i] = arr[i];
	}
	begin = clock();
	quicksort(arrCopy, size);
	end = clock();
	printf("quicksort: %d\n",end-begin);
	
	CopyFirst(arr, arrCopy, size);
	begin = clock();
	mergesort(arrCopy, size);
	end = clock();
	printf("mergesort: %d\n",end-begin);
	
	CopyFirst(arr, arrCopy, size);
	begin = clock();
	selectionsort(arrCopy, size);
	end = clock();
	printf("Selektionsort: %d\n",end-begin);
	
	CopyFirst(arr, arrCopy, size);
	begin = clock();
	insertionsort(arrCopy, size);
	end = clock();
	printf("Insertionsort: %d\n",end-begin);
	
	CopyFirst(arr, arrCopy, size);
	begin = clock();
	bubblesort(arrCopy, size);
	end = clock();
	printf("Bubblesort: %d\n",end-begin);

	free(arr);
	free(arrCopy);
	
	return 0;
}
Beispiel #2
0
int use_copy_first(tList *TL, int *ElemValue)	{
/* O¹etøuje pou¾ití operace CopyFirst. */
	int tmp;
	CopyFirst(TL,&tmp);
	
	if (!solved)	{
		printf("Operace CopyFirst nebyla implementována!\n");
		return(FALSE);
	}
	else {
		if (errflg)	{
			printf("Operace CopyFirst volala funkci Error.\n");
			errflg=FALSE;
			return(FALSE);
		}	
		else	{	 
			*ElemValue=tmp;			
			printf("Operace CopyFirst vrací obsah %d.\n",tmp);
			return(TRUE);
		}	
	}	
}
Beispiel #3
0
expand_symlinks P1C(char *, s)
{
  static char pre[BSIZE];	/* return value */
  char post[BSIZE], sym[BSIZE], tmp[BSIZE], before[BSIZE];
  char *cp;
  char a;
  struct stat st;
  int done;

  /* Check for symlink loops.  It's difficult to check for all the
     possibilities ourselves, so let the kernel do it.  And make it
     conditional so that people can see where the infinite loop is
     being caused (see engtools#1536).  */
  if (!ll_loop) {
    FILE *f = fopen (s, "r");
    if (!f && errno == ELOOP) {
      /* Not worried about other errors, we'll get to them in due course.  */
      perror (s);
      return NULL;
    }
    if (f) fclose (f);
  }

  strcpy (post, s);
  strcpy (pre, "");

  while (strlen (post) != 0) {
    CopyFirst (pre, post);

    if (lstat (pre, &st) != 0) {
      fprintf (stderr, "lstat(%s) failed ...\n", pre);
      perror (pre);
      return NULL;
    }

    if (S_ISLNK (st.st_mode)) {
      ReadSymLink (pre, sym);

      if (!strncmp (sym, "/", 1)) {
        if (ll_verbose)
          printf ("[%s]%s%s -> [%s]%s%s\n", pre, EXPOS, post, sym, EXPOS,post);
        strcpy (pre, "");

      } else {
        a = pre[0];	/* handle links through the root */
        strcpy (tmp, StripLast (pre));
        if (!strlen (pre) && a == '/')
          strcpy (pre, "/");

        if (ll_verbose) {
          sprintf (before, "%s%s[%s]%s%s", pre, EXPRE, tmp, EXPOS, post);
          printf ("%s -> %s%s[%s]%s%s\n", before, pre, EXPRE, sym, EXPOS,post);
        }

        /* Strip "../" path elements from the front of sym; print
           new result if there were any such elements.  */
        done = 0;
        a = pre[0];	/* handle links through the root */
        while (!strncmp (sym, "..", 2)
               && (sym[2] == 0 || sym[2] == '/')
               && strlen (pre) != 0
               && strcmp (pre, ".")
               && strcmp (pre, "..")
               && (strlen (pre) < 3
                   || strcmp (pre + strlen (pre) - 3, "/.."))) {
          done = 1;
          StripFirst (sym);
          StripLast (pre);
        }

        if (done && ll_verbose) {
          for (cp = before; *cp;)
            *cp++ = ' ';
          if (strlen (sym))
            printf ("%s == %s%s%s%s%s\n", before, pre, EXPRE, sym, EXPOS,post);
          else
            printf ("%s == %s%s%s\n", before, pre, EXPOS, post);
        }
        if (!strlen (pre) && a == '/')
          strcpy (pre, "/");
      }

      if (strlen (post) != 0 && strlen (sym) != 0)
        strcat (sym, "/");

      strcat (sym, post);
      strcpy (post, sym);
    }
  }

  return pre;
}