      programsortt
      dimensionindex(64),it(8),kar(64)
      write(3,5)
5     format(1x,23hHow many shall we sort?)
      read(3,10)n
10    format(i2)
      do 23000i=1,n
      kar(i)=(sin(float(i))+1.)*16384.
23000 continue
23001 continue
      callsorti(kar,index,n)
      write(3,20)
20    format(1x,18hIndexed test array)
      do 23002i=1,n,8
      do 23004j=1,8
      ji=i+j-1
      ixj=index(ji)
      it(j)=kar(ixj)
23004 continue
23005 continue
      write(3,30)it
23002 continue
23003 continue
30    format(8i6)
      stop
      end
      subroutinesorti(a,ix,n)
      dimensiona(n),ix(n),i(13),l(13)
      integera
      do 23006j=1,n
      ix(j)=j
23006 continue
23007 continue
      m=1
      i(1)=1
      l(1)=n
      continue
23008 continue
      im=i(m)
      j=im
      k=l(m)+1
      if(.not.(k.lt.j+2))goto 23011
      m=m-1
      goto 23012
23011 continue
      ixim=ix(j)
      continue
23013 continue
      j1=j+1
      k1=k-1
      do 23016j=j1,k1
      ixj=ix(j)
      if(.not.(a(ixim).lt.a(ixj)))goto 23018
      goto120
23018 continue
23016 continue
23017 continue
      goto 23015
120   continue
23020 continue
      k=k-1
      ixk=ix(k)
23021 if(.not.(a(ixim).ge.a(ixk)))goto 23020
23022 continue
      k=max0(k,j)
      if(.not.(k.eq.j))goto 23023
      goto 23015
23023 continue
      it=ix(j)
      ix(j)=ix(k)
      ix(k)=it
23014 goto 23013
23015 continue
      ix(im)=ix(k-1)
      ix(k-1)=ixim
      if(.not.(k*2-l(m)-im.lt.2))goto 23025
      i(m+1)=im
      i(m)=k
      l(m+1)=k-2
      goto 23026
23025 continue
      i(m+1)=k
      l(m+1)=l(m)
      l(m)=k-2
23026 continue
      m=m+1
      if(.not.(m.gt.13))goto 23027
      write(3,90)
23027 continue
90    format(1x,45hNumber of segments in quicksort exceeds MAXM )
23012 continue
23009 if(.not.(m.lt.1.or.m.gt.13))goto 23008
23010 continue
      return
      end
