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 does -> symbol indicates in Perl?
What are the various perl data types based on the context?
Explain the default scope of variables in perl?
You want to open and read data files with perl. How would you do that?
Explain the meaning of closure in perl.
Which of these is a difference between Perl and C++ ?
Explain the use of 'my' keyword in perl?
How many data types are there in perl?
What happens in dereferencing?
How to open a directory in perl?
What package you use to create a windows services?
Can you add two arrays together?
How can I display all array element in which each element will display on next line in perl ?
Give an example of using the -n and -p option.
Suppose an array contains @arraycontent=(‘ab’, ‘cd’, ‘ef’, ‘gh’). How to print all the contents of the given array?