Solve the following problems
Problem 1
Write a program to sort an array of strings. For
this write a function sort()
which will take the array of Strings as argument and sort the array. It
should not return any thing i.e. return value of sort() is 'void'. In the main() function print the sorted
array of strings.
Hint :
Use compareTo() method of the String class to compare two strings.The result is a negative integer if this
public int compareTo(String anotherString)
String
object lexicographically precedes the argument string. The result is a
positive integer if this String
object lexicographically
follows the argument string. The result is zero if the strings are
equal;
Problem 2
Remove all duplicates from an array. For example,
if the array has the values
4 7 11
4 9 5 11 7 3 5
then the array should be changed to
4 7
11 9 5 3.
Write a function which removes the duplicates and return a new array
with the duplicates removed. While removing duplicates DO NOT sort the
array. Print the values of the returned array in the main( ) function.
11 |
18 |
25 |
2 |
9 |
10 |
12 |
19 |
21 |
3 |
4 |
6 |
13 |
20 |
22 |
23 |
5 |
7 |
14 |
16 |
17 |
24 |
1 |
8 |
15 |