Newsgroups: fj.lang.c
Path: galaxy.trc.rwcp.or.jp!coconuts.jaist!wnoc-tyo-news!aist-nara!odins-suita!chiba-ns!hagi!is.tsukuba.ac.jp!kaburagi
From: kaburagi@darwin.esys.tsukuba.ac.jp (Yasuhiro Kaburagi)
Subject: =?ISO-2022-JP?B?GyRCSiwzZCUzJXMlUSUkJWsbKEI=?=
Date: Wed, 12 Feb 1997 17:30:15 GMT
Mime-Version: 1.0
Nntp-Posting-Host: darwin.esys.tsukuba.ac.jp
X-Newsreader: mnews [version 1.19PL2] 1996-01/26(Fri)
Content-Type: text/plain; charset=ISO-2022-JP
Organization: Institute of Engineering Mechanics, University of Tsukuba, Japan
Sender: news@is.tsukuba.ac.jp (News Manager)
Message-ID: <1997Feb12.173015.25338@is.tsukuba.ac.jp>
Lines: 94
Xref: galaxy.trc.rwcp.or.jp fj.lang.c:3608
X-originally-archived-at: http://galaxy.rwcp.or.jp/text/cgi-bin/newsarticle2?ng=fj.lang.c&nb=3608&hd=a
X-reformat-date: Mon, 18 Oct 2004 15:18:22 +0900
X-reformat-comment: Tabs were expanded into 4 column tabstops by the Galaxy's archiver. See http://katsu.watanabe.name/ancientfj/galaxy-format.html for more info.


   $B$O$8$a$^$7$F!#E-LZ!wC^GHBg3X$H$$$$$^$9!#(B

    $B8=:_(BSolaris2.5$B$G%W%m%0%i%`$r=q$$$F$$$^$9!#(B

    $B$=$3$G!"J,3d%3%s%Q%$%k$K4X$7$F$h$/J,$+$i$J$$$3$H$,$"$C$?$N$G(B
  $B$b$7J,$+$kJ}$,$$$i$7$?$i!"65$($F$$$?$@$-$?$$$H;W$$$^$7$F!"$3$3$X(B
  $BEj9F$7$^$7$?!#(B
   $B%=!<%9%U%!%$%k$O:G8e$K$"$j$^$9$N$G!"%A%'%C%/$7$F$$$?$@$1$k$H(B
  $B$&$l$7$$$G$9!#(B

    $B;HMQ$7$F$$$k%3%s%Q%$%i$O!"(B

     /gcc-lib/sparc-sun-solaris2.5/2.7.2.1/specs
     gcc version 2.7.2.1

   $B$G$9!#(B
    
   $BLdBj$O(B

     % cc main.c quicksort.c

   $B$H$9$k$H!"$A$c$s$H!V(Ba.out$B!W%U%!%$%k$,$G$-$F!"(B

     % a.out out

   $B$J$I$H$7$F!"$-$A$s$HK>$s$@$b$N$,!V(Bout$B!W%U%!%$%k$KF~$k$N$G$9$,!"(B

     % cc -c main.c
     % cc -c quicksort.c
     % ld main.o quicksort.o -lc

   $B$H$9$k$H(B,$B:#EY$O(B

    % a.out out
    Segmentation fault 

   $B$H$J$C$F$7$^$$$^$9!#(B

   $B$J$<$J$N$G$7$g$&$+!)!#8fB8CN$NJ}!"65$($F$/$@$5$$!#(B

-----------------$B!V(Bmain.c$B!W(B----------------------------------
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>

extern void quicksort( int*,int,int);

void  main( int argc , char **argv)
{
  struct timeval   start,end;
  int              a[]={ 0,1,2,3,4,5,6,7,8,9};
  FILE             *fp;
  
  fp = fopen( argv[1],"w+" );

  gettimeofday( &start,NULL );
  
  quicksort( a , 0 , 9 );

  gettimeofday( &end,NULL );
      
  fprintf( fp, "Time %020d\n",end.tv_usec-start.tv_usec );
}



------------$B!V(Bquicksort.c$B!W(B--------------------------------
void quicksort( int *a, int first, int last)
{
  int   i,j;
  int   x,t;

  x=a[(first +last)/2];
  i=first;
  j=last;

  for( ; ; )
    {
      while( a[i] < x ) i++;
      while( x < a[j] ) j--;
      if ( i >= j )break;
      t=a[i];
      a[i]=a[j];
      a[j]=t;
      i++;
      j--;
    }

  if( first < i-1 ) quicksort( a, first, i-1 );
  if( j + 1 < last )quicksort( a, j+1, last );
}


