      SUBROUTINE SORTDG (STK1,STK2,X1,X2,NDEG)
C
C     SORTDG SORTS STK2 BY DEGREE OF THE NODE AND ADDS IT TO THE END
C     OF STK1 IN ORDER OF LOWEST TO HIGHEST DEGREE.  X1 AND X2 ARE THE
C     NUMBER OF NODES IN STK1 AND STK2 RESPECTIVELY.
C
      INTEGER          X1,       X2,       STK1,     STK2,     TEMP
      DIMENSION        NDEG(1),  STK1(1),  STK2(1)
      COMMON /BANDG /  N,        IDPTH
C
      IND=X2
   10 ITEST=0
      IND=IND-1
      IF (IND.LT.1) GO TO 40
      DO 30 I=1,IND
      J=I+1
      ISTK2=STK2(I)
      JSTK2=STK2(J)
      IF (NDEG(ISTK2).LE.NDEG(JSTK2)) GO TO 30
      ITEST=1
      TEMP=STK2(I)
      STK2(I)=STK2(J)
      STK2(J)=TEMP
   30 CONTINUE
      IF (ITEST.EQ.1) GO TO 10
   40 DO 50 I=1,X2
      X1=X1+1
      STK1(X1)=STK2(I)
   50 CONTINUE
      RETURN
      END
