sort a word "system" in perl/shell without using built in
functions
output should be emssty
Answer Posted / umesh
$value = "system";
@SortedArray = split('',$value);
$strlength = @SortedArray;
print "Current sort @SortedArray
";
$swapped = 0;
for($i=0; $i < $strlength; $i++){
for (my $j = 0; $j < $strlength-1-$i; $j++) {
if($SortedArray[$j] gt $SortedArray[$j+1]){
$tmp = $SortedArray[$j];
$SortedArray[$j] = $SortedArray[$j+1];
$SortedArray[$j+1] = $tmp;
$swapped =1;
}
}
if ($swapped) {
next;
}
}
print join('', split(' ', "@SortedArray")), "
";
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is the use of 'ne' operator?
what are the two ways to get private values inside a subroutine or block?
Comment on the scope of variables in perl.
what is the difference between java and cgi?
Mention the difference between die and exit in Perl?
What is the different between array and hash in perl programming?
How to open and read data files with Perl
What does next statement do in perl?
How do I sort a hash by the hash key?
What does 'do' statement do in perl?
What are perl array functions?
What is the use of now constructor in perl?
What is warn function in perl?
Mention how many ways you can express string in Perl?
Differentiate between c++ and perl.