-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayQue1.sh
48 lines (37 loc) · 1.01 KB
/
ArrayQue1.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash/ -x
MAXCOUNT=10
count=1
while [ "$count" -le $MAXCOUNT ]
do
number[$count]=$((RANDOM%900 + 100))
let "count += 1"
done
echo ${number[@]}
largest=${number[0]}
secondGreatest='unset'
for((i=1; i < ${#number[@]}; i++))
do
if [[ ${number[i]} > $largest ]]
then
secondGreatest=$largest
largest=${number[i]}
elif (( ${number[i]} != $largest )) && { [[ "$secondGreatest" = "unset" ]] || [[ ${number[i]} > $secondGreatest ]]; }
then
secondGreatest=${number[i]}
fi
done
echo "Second Largest Number: $secondGreatest"
smallest=${number[0]}
secondSmallest='unset'
for((i=1; i < ${#number[@]}; i++))
do
if [[ ${number[i]} < $smallest ]]
then
secondSmallest=$smallest
smallest=${number[i]}
elif { [[ "$secondSmallest" = "unset" ]] || [[ ${number[i]} < $secondSmallest ]]; }
then
secondSmallest=${number[i]}
fi
done
echo "Second Smallest Number: $secondSmallest"