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}")
 [ ] 

Monday, November 21, 2011

Delete element from List

Deleting element from list-Element can be deleted from list using silktest ListDelete function

ListDelete(List of string, index)

However if you want to delete by name then here is the sample code

LIST OF STRING lString = {"Apple", "Orange", "Mango", "Guava"}
int i= 1
LIST OF STRING temp = {...}
while(i <= ListCount(lString)
  if lString[i] = "Mango"
      ListDelete(lString, i)
  else
     ListAppend(temp, lString[i])
      i++
print(temp)


// Delete duplicate element from list

 [ ] LIST OF STRING ls = {"11", "33", "44", "55", "33", "88", "33"}
 [ ] List of STRING temp = {...}
 [ ] int i=1, j, count = 0
 [-] for j = 1 to listcount(ls)
  [-] if ls[j] == "33"
   [ ] count = count + 1
 [ ] 
 [-] while(i <= listcount(ls))
  [ ] 
  [-] if (ls[i] == "33" && count >> 1)
   [ ] listdelete(ls, i)
   [ ] count --
  [-] else
   [ ] listappend(temp, ls[i])
   [ ] i++
  [ ] 
 [ ] print(temp)