Hi, which sorting algorithm can be used to get nearer and aproximate matching list with given string input: 1. list of strings 2. tobesearch_str
+5
A:
My understanding of what it is you want to do is as follows:
- You have a TCL list that contains a number of strings
- You have a search string that does not exactly match any of the strings in your list
- You want to sort the strings in the list by how close they are to the search string.
One way of measuring how close two strings are is the edit or Levevshtein distance. There is a page on the TCL wiki that gives a TCL implementaion of this algorithm. What you can then do is create a list of lists where each sub-list contains you candidate string and its distance from the search string. The code below shows how sort this list using the lsort command:
set myList [list {AADD 3} {AABC 2} {AAAB 1} {DCBA 4}]
puts $myList
set sortedList [lsort -integer -index 1 $myList]
puts $sortedList
This results in the following output:
{AADD 3} {AABC 2} {AAAB 1} {DCBA 4}
{AAAB 1} {AABC 2} {AADD 3} {DCBA 4}
Is this the kind of thig you are after or have I misinterpreted what you are trying to do?
Jackson
2010-02-15 10:57:24
yes that is perfet answer what I am looking for...Thanks.
OliveOne
2010-02-15 11:54:19
+1 for good ESP
glenn jackman
2010-02-15 16:23:40