A function in shell script,how can i get the right result

there is a directory /data/users/osa/psidp/dmp/files/cimdir ,it have some subdirectories ,and also the subdirectoriy have it's subdirectoriis.
I want to get all the leaf nodes of the directory path .
but the result of the script is wrong ,how can i get the right result

somebody who can help me !!!!

the script name is fw.sh :

hanshu()
{
dirnum=`find $1 -type d|wc -l`
if [ $dirnum != 1 ]; then
set -A subDir `ls -l $1| awk '{if (substr($0,1,1)~"d") print $8}'`
typeset -i i
i=0
while [ $i -lt $dirnum ]
do
subDir[$i]=$1"/"${subDir[$i]}
hanshu ${subDir[$i]}
if [ "${subDir[$i]}" != "" ]; then
echo "/"${subDir[$i]}
fi
i=`expr $i + 1`
done
fi
}
hanshu $1

for example,when i run

fw.sh /data/users/osa/psidp/dmp/files/cimdir

i want get the value is :

//data/users/osa/psidp/dmp/files/cimdir/scm/1.04
//data/users/osa/psidp/dmp/files/cimdir/scm_version
//data/users/osa/psidp/dmp/files/cimdir/version

but the anwser is :

//data/users/osa/psidp/dmp/files/cimdir/scm/1.04
//data/users/osa/psidp/dmp/files/cimdir/scm/1.04

how can i get the right result what i want?
thanks!

How about this:

#!/bin/ksh
# leaf nodes in a directory tree 
#example directory

cd $HOME/workfiles

set -A nodes $(find . -type d | tr -s '\n' ' ')

if [[  ${#nodes[*]} -eq 1 ]] ; then
   echo $(pwd) " is a leaf node"
   exit
fi

let i=0

end=${#nodes[*]}
while [[ $i -lt $end ]]
do
      set -A checknode $(find ${nodes} -type d )
      if [[  ${#checknode[*]} -eq 1 ]] ; then
         echo "Leaf node for $(pwd):" ${checknode[0]}                     
      fi                                 
      i=$(( i = $i + 1 ))
done

What about just using the find command in this way:

find $start_directory -type d

This should list out all the directories/subdirectories under $start_directory

the two answers is right !
i can use them now