Tuesday, November 22, 2011

Sort list of list and list


// sort list of list 

 [ ] LIST OF LIST OF STRING list1 = {{"88", "Right"}, {"44", "Test"}, {"11", "Hit"}}
 [ ] List OF STRING ls1
 [ ] 
 [ ] integer i,j,k
 [ ] k= listcount(list1)
 [-] for(i=1; i <=k; i++)
  [-] for(j=i+1; j<=k; j++)
   [-] if(val(list1[i][1]) > val(list1[j][1]))
    [ ] ls1 = list1[j]// if list[1][1] 
    [ ] list1[j] = list1[i]
    [ ] list1[i] = ls1 
 [ ] print(list1)

// sort list
 [ ] List OF STRING ls1 = {"9", "99", "2", "55", "100"}
 [ ] STRING s
 [ ] print(ls1)
 [ ] int x,y, z
 [ ] z = ListCount(ls1)
 [-] for(x = 1; x <=z; x++)
  [-] for(y=x+1; y<=z; y++)
   [-] if(val(ls1[x]) >  val(ls1[y]))
    [ ] s = ls1[y]
    [ ] ls1[y] = ls1[x]
    [ ] ls1[x] = s
 [ ] print(ls1)

// reverse strinf

 [ ] STRING s = "abcdefghijklmn1234xyz"
 [ ] int i, j=1
 [ ] i = len(s)
 [ ] STRING r = Right(s, 1)
 [-] while( j < i)
  [ ] r+ = SubStr(s, i-j, 1)
  [ ] j++
 [ ] print(r)

// Length of String with out Len() function

 [ ] STRING s1 = "abcdefghijkl"
 [ ] STRING r1
 [ ] int count1 = 0, n=1
 [-] // while(s1[n] != "") // while(s1[n] !=Null or '\0')  will throw error as "" will not be zero index is out of valid range
  [ ] // count1++
  [ ] // n++
 [-] for(n = 1; s1[n] != ""; n++) 
  [ ] count1++
 [ ] 
 [ ] print("length of {s1} is:{ count1}")
 [ ] 

No comments:

Post a Comment