java - Quadratic sort of ArrayList -


i have been attempting use quadratic sort in java, sort arraylist of messages. have used following code, not compile me. error keep getting

cannot find symbol variable length

below sort , swap using:

 public static void quadraticsort(arraylist<message> m)   {     string s1 = "abcd";     string s2 = "efgh";     int val = "abcd".compareto("efgh");      (int = 0; < s1.length; += 1)     {         (int s2 = i; s2 < s1.length; s2 += 1)        {            if ((int)s1[s2].messagetext.compareto(0) <(int)s2[i].messagetext.compareto(0))             {                swap(s1, i, s2);            }         }      }  }  private static void swap(arraylist<message> list, int to, int from) {    message temp = list[to];    list.set(to , from);    list.set(from , temp); } 

in code you're trying access length property/field of string instances, not exist. instead, want use length() method:

string s = "abc"; s.length(); // = 3 s.length; // compiler error 

but have more bugs that. you're attempting access indexed value of string using array/bracket notation:

s1[s2]

the characters of string objects not accessible in manner. should use charat() method instead.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -