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 peculiarity of returning values by subroutines in perl?
Which of these is a difference between Perl and C++ ?
Who created perl?
Comment on data types and variables in perl.
How to create a package?
How to change a directory in perl?
What are the purpose of close(), getc() and read() functions?
“The methods defined in the parent class will always override the methods defined in the base class”. What does this statement means?
What does read () command do?
What is 'commit' command in perl?
How to start perl in interactive mode?
What are the advantages of perl programming?
How many loop control keywords are there in perl?
Explain grooving and shortening of arrays?
What happens in dereferencing?