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
Explain perl one-liner?
In CPAN module, name an instance you use.
Write a program that shows the distinction between child and parent process?
Why do you use Perl?
what are steps to do to lock the sony ericsson mobile with password?
How to code in perl to implement the tail function in unix?
what are the three groups involved in information sharing?
What is 'rollback' command in perl?
Which of these is a difference between Perl and C++ ?
Mention what is cpan?
What is posix in perl?
Elaborate on perl bite-wise operators.
What syntax is used for grep() function?
How to add elements in a hash in perl?
You want to open and read data files with perl. How would you do that?