Advertisement
Shailrshah

Sort Command-Line inputted Strings using Insertion Sort

Oct 29th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. class sortStrings{
  2.     static void sort(String[] words){
  3.         int i, j;
  4.         for(i = 1; i < 10; i++){
  5.             String temp = words[i];
  6.             for(j = i -1; j>=0 && temp.compareToIgnoreCase(words[j])<0; j--)
  7.                 words[j+1] = words[j];
  8.             words[j+1] = temp;
  9.         }
  10.     }
  11.     public static void main(String[] args){
  12.         String[] words = new String[10];
  13.         for(int i = 0; i< 10; i++) words[i] = args[i];
  14.         sort(words);
  15.         for(int i = 0; i<10; i++)
  16.             System.out.println(words[i]);
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement