#!/bin/sh # This is a shell archive (produced by GNU sharutils 4.2.1). # To extract the files from this archive, save it to some FILE, remove # everything before the `!/bin/sh' line above, then type `sh FILE'. # # Made on 2008-02-21 23:45 EST by . # Source directory was `/home/u8/skiena/html/373/programs'. # # Existing files will *not* be overwritten unless `-c' is specified. # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 438 -rw-r--r-- 2-to-n.c # 553 -rw-r--r-- binary-search.c # 478 -rw-r--r-- fac_time.c # 585 -rw-r--r-- insert-sort.c # 821 -rw-r--r-- merge-sort.c # 330 -rw-r--r-- seq-search.c # 312 -rw-r--r-- triple.c # save_IFS="${IFS}" IFS="${IFS}:" gettext_dir=FAILED locale_dir=FAILED first_param="$1" for dir in $PATH do if test "$gettext_dir" = FAILED && test -f $dir/gettext \ && ($dir/gettext --version >/dev/null 2>&1) then set `$dir/gettext --version 2>&1` if test "$3" = GNU then gettext_dir=$dir fi fi if test "$locale_dir" = FAILED && test -f $dir/shar \ && ($dir/shar --print-text-domain-dir >/dev/null 2>&1) then locale_dir=`$dir/shar --print-text-domain-dir` fi done IFS="$save_IFS" if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED then echo=echo else TEXTDOMAINDIR=$locale_dir export TEXTDOMAINDIR TEXTDOMAIN=sharutils export TEXTDOMAIN echo="$gettext_dir/gettext -s" fi if touch -am -t 200112312359.59 $$.touch >/dev/null 2>&1 && test ! -f 200112312359.59 -a -f $$.touch; then shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"' elif touch -am 123123592001.59 $$.touch >/dev/null 2>&1 && test ! -f 123123592001.59 -a ! -f 123123592001.5 -a -f $$.touch; then shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"' elif touch -am 1231235901 $$.touch >/dev/null 2>&1 && test ! -f 1231235901 -a -f $$.touch; then shar_touch='touch -am $3$4$5$6$2 "$8"' else shar_touch=: echo $echo 'WARNING: not restoring timestamps. Consider getting and' $echo "installing GNU \`touch', distributed in GNU File Utilities..." echo fi rm -f 200112312359.59 123123592001.59 123123592001.5 1231235901 $$.touch # if mkdir _sh29180; then $echo 'x -' 'creating lock directory' else $echo 'failed to create lock directory' exit 1 fi # ============= 2-to-n.c ============== if test -f '2-to-n.c' && test "$first_param" != -c; then $echo 'x -' SKIPPING '2-to-n.c' '(file already exists)' else $echo 'x -' extracting '2-to-n.c' '(text)' sed 's/^X//' << 'SHAR_EOF' > '2-to-n.c' && #include #include X X int main(argc,argv) int argc; char* argv[]; { X int n; X unsigned long long i,counter; X if (argc==1) X { X printf("\nUsage: temp -n\n n:The range of elements to consider\n"); X exit(0); X } X n=atoi(argv[1]); X if ((n / 8) >= (sizeof(counter))) X { X printf("\nUsage: n must not exceed %d on your machine.\n", sizeof(counter) * 8 - 1); X return; X } X counter=pow(2,n); X for(i=0;i<=counter;i++); X return 0; } X SHAR_EOF (set 20 08 02 21 23 45 12 '2-to-n.c'; eval "$shar_touch") && chmod 0644 '2-to-n.c' || $echo 'restore of' '2-to-n.c' 'failed' if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \ && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then md5sum -c << SHAR_EOF >/dev/null 2>&1 \ || $echo '2-to-n.c:' 'MD5 check failed' 9c24347c5049293c480402eaa7eb0607 2-to-n.c SHAR_EOF else shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < '2-to-n.c'`" test 438 -eq "$shar_count" || $echo '2-to-n.c:' 'original size' '438,' 'current size' "$shar_count!" fi fi # ============= binary-search.c ============== if test -f 'binary-search.c' && test "$first_param" != -c; then $echo 'x -' SKIPPING 'binary-search.c' '(file already exists)' else $echo 'x -' extracting 'binary-search.c' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'binary-search.c' && #include #include X X int main(argc,argv) int argc; char* argv[]; { int n,element_to_find,i,key,last,first; X if (argc==1) { X printf("\nUsage: temp -n\n n:The range of elements to consider\n"); X exit(0); } n=atoi(argv[1]); srand(time(NULL)); for(i=0;i<100;i++) X element_to_find=rand()%n; i=0; //Set i to 1 when element is found last=n; first=0; X while((!i) && (firstkey) X first=key; X else if(element_to_find&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \ && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then md5sum -c << SHAR_EOF >/dev/null 2>&1 \ || $echo 'binary-search.c:' 'MD5 check failed' 4e7f7882ee87f1998c38b896fdadb59d binary-search.c SHAR_EOF else shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'binary-search.c'`" test 553 -eq "$shar_count" || $echo 'binary-search.c:' 'original size' '553,' 'current size' "$shar_count!" fi fi # ============= fac_time.c ============== if test -f 'fac_time.c' && test "$first_param" != -c; then $echo 'x -' SKIPPING 'fac_time.c' '(file already exists)' else $echo 'x -' extracting 'fac_time.c' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'fac_time.c' && #include #include #include X X int main(argc,argv) int argc; char* argv[]; { long n,n2,i,j,fact,fact2; X if (argc==1) { X printf("\nUsage: temp -n\n n:The range of elements to consider\n"); X exit(0); } n=atoi(argv[1]); X if (n > 16) { X n = 16; X n2 = (n > 26) ? 26 : n; } else { X n2 = 1; } X fact2 = 1; for (j=17; j<=n2; j++) X fact2= fact2 * j; X for(j=1; j<= fact2; j++) { X fact=1; X for(i=1;i<=n;i++) X fact=fact*i; X X for(i=0;i<=fact;i++); } X return 0; } SHAR_EOF (set 20 00 08 14 16 23 56 'fac_time.c'; eval "$shar_touch") && chmod 0644 'fac_time.c' || $echo 'restore of' 'fac_time.c' 'failed' if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \ && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then md5sum -c << SHAR_EOF >/dev/null 2>&1 \ || $echo 'fac_time.c:' 'MD5 check failed' cbd6d03427997f10e408ef2a7d7f07ff fac_time.c SHAR_EOF else shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'fac_time.c'`" test 478 -eq "$shar_count" || $echo 'fac_time.c:' 'original size' '478,' 'current size' "$shar_count!" fi fi # ============= insert-sort.c ============== if test -f 'insert-sort.c' && test "$first_param" != -c; then $echo 'x -' SKIPPING 'insert-sort.c' '(file already exists)' else $echo 'x -' extracting 'insert-sort.c' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'insert-sort.c' && #include #include #include X X X void insert_sort(int *array,int n){ int i,j,temp; X for(i=1;i<=(n-1);i++) X { X temp=array[i]; X j=i; X while((j>0) && (array[j-1]>temp)){ X array[j]=array[j-1]; X j--; X } X array[j]=temp; X } } X X int main(argc,argv) int argc; char *argv[]; { int n,element_to_find,i,*array; X if (argc==1) { X printf("\nUsage: temp -n\n n:The range of elements to consider\n"); X exit(0); } n=atoi(argv[1]); srand(time(NULL)); array=(int*)malloc(sizeof(int)*n); for(i=0;i<=(n-1);i++){ X array[i]=rand(); } insert_sort(array,n); } SHAR_EOF (set 20 00 08 14 16 23 56 'insert-sort.c'; eval "$shar_touch") && chmod 0644 'insert-sort.c' || $echo 'restore of' 'insert-sort.c' 'failed' if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \ && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then md5sum -c << SHAR_EOF >/dev/null 2>&1 \ || $echo 'insert-sort.c:' 'MD5 check failed' c56926de718d01bec43ba686cbef5859 insert-sort.c SHAR_EOF else shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'insert-sort.c'`" test 585 -eq "$shar_count" || $echo 'insert-sort.c:' 'original size' '585,' 'current size' "$shar_count!" fi fi # ============= merge-sort.c ============== if test -f 'merge-sort.c' && test "$first_param" != -c; then $echo 'x -' SKIPPING 'merge-sort.c' '(file already exists)' else $echo 'x -' extracting 'merge-sort.c' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'merge-sort.c' && #include #include #include X int *aux_array; X void mergesort(int array[],int l,int r){ int i,j,k,m; X if (r>l){ X m=(r+l)/2; X mergesort(array,l,m); X mergesort(array,m+1,r); X for(i=m+1;i>l;i--) aux_array[i-1]=array[i-1]; X for(j=m;j&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \ && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then md5sum -c << SHAR_EOF >/dev/null 2>&1 \ || $echo 'merge-sort.c:' 'MD5 check failed' e3740e7200e6aa2a704e8d267b5cc01d merge-sort.c SHAR_EOF else shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'merge-sort.c'`" test 821 -eq "$shar_count" || $echo 'merge-sort.c:' 'original size' '821,' 'current size' "$shar_count!" fi fi # ============= seq-search.c ============== if test -f 'seq-search.c' && test "$first_param" != -c; then $echo 'x -' SKIPPING 'seq-search.c' '(file already exists)' else $echo 'x -' extracting 'seq-search.c' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'seq-search.c' && #include #include #include X X int main(argc,argv) int argc; char* argv[]; { long n,element_to_find,i; X if (argc==1) { X printf("\nUsage: temp -n\n n:The range of elements to consider\n"); X exit(0); } X n=atoi(argv[1]); X element_to_find = n/2; X i=0; while ((i<=n) && (i!=element_to_find)) i++; X return 0; } SHAR_EOF (set 20 00 08 14 16 23 56 'seq-search.c'; eval "$shar_touch") && chmod 0644 'seq-search.c' || $echo 'restore of' 'seq-search.c' 'failed' if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \ && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then md5sum -c << SHAR_EOF >/dev/null 2>&1 \ || $echo 'seq-search.c:' 'MD5 check failed' 97248a55f2318865d1944d490f3984ea seq-search.c SHAR_EOF else shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'seq-search.c'`" test 330 -eq "$shar_count" || $echo 'seq-search.c:' 'original size' '330,' 'current size' "$shar_count!" fi fi # ============= triple.c ============== if test -f 'triple.c' && test "$first_param" != -c; then $echo 'x -' SKIPPING 'triple.c' '(file already exists)' else $echo 'x -' extracting 'triple.c' '(text)' sed 's/^X//' << 'SHAR_EOF' > 'triple.c' && #include #include #include X X int main(argc,argv) int argc; char* argv[]; { int n,i,j,k,t; X if (argc==1) { X printf("\nUsage: temp -n\n n:The range of elements to consider\n"); X exit(0); } n=atoi(argv[1]); for(i=0;i<=n;i++) X for(j=0;j<=n;j++) X for(k=0;k<=n;k++) X t++; X return 0; } SHAR_EOF (set 20 00 08 14 16 23 56 'triple.c'; eval "$shar_touch") && chmod 0644 'triple.c' || $echo 'restore of' 'triple.c' 'failed' if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \ && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then md5sum -c << SHAR_EOF >/dev/null 2>&1 \ || $echo 'triple.c:' 'MD5 check failed' 86d433ab5e9288180262e84adb82e94d triple.c SHAR_EOF else shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'triple.c'`" test 312 -eq "$shar_count" || $echo 'triple.c:' 'original size' '312,' 'current size' "$shar_count!" fi fi rm -fr _sh29180 exit 0