Advertisement
pastebinuser124

Untitled

Apr 5th, 2025
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.27 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function rec {
  4.   local x=$1
  5.   if test $1 -lt 5
  6.   then
  7.     ((x++))
  8.     echo "rec $x"
  9.     rec $x
  10.   else
  11.     echo $x
  12.   fi
  13. }
  14.  
  15. function makedirs {
  16.     mkdir -p 1/2/5 1/2/6 1/3 1/4/7 1/4/8
  17. }
  18.  
  19. function getsubdirs {
  20.     subdirs=()
  21.     currentdir="$1"
  22.     for i in "$currentdir"/*;do
  23.         if test -d "$i"; then
  24.             #~ echo addsub "$i" 1>&2
  25.             subdirs+=("$i")
  26.         fi
  27.     done
  28. }
  29.  
  30. function printcontent {
  31.     for i in "$1"/*; do
  32.         echo $i
  33.         #~ echo "`du -h "$i"|cut -f1`" "$i"
  34.     done
  35. }
  36.  
  37. function dfspreorder {
  38.     local currentdir="$1"
  39.     echo preorder "$1"
  40.     getsubdirs "$currentdir"
  41.     for subdir in "${subdirs[@]}"; do
  42.         dfspreorder "$subdir"
  43.         #~ echo inorder "$currentdir"
  44.     done
  45.     #~ echo postorder "$currentdir"
  46. }
  47.  
  48. function dfsinorder {
  49.     local currentdir="$1"
  50.     getsubdirs "$currentdir"
  51.     for subdir in "${subdirs[@]}"; do
  52.         dfsinorder "$subdir"
  53.         echo inorder for "$currentdir"
  54.     done
  55.     echo inorder afterfor "$currentdir"
  56. }
  57.  
  58. function dfspostorder {
  59.     local currentdir="$1"
  60.     getsubdirs "$currentdir"
  61.     for subdir in "${subdirs[@]}"; do
  62.         dfspostorder "$subdir"
  63.     done
  64.     echo postorder "$currentdir"
  65. }
  66.  
  67. count=0
  68. subdirs=()
  69. #rec 0
  70. #recdir `pwd`
  71. rm -rf 1
  72. makedirs
  73. root=`realpath 1`
  74.  
  75. dfspreorder "$root" #ok
  76. dfspostorder "$root" #ok
  77. dfsinorder "$root" #ok
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement