search

inserting in binary tree doesn't work using java

流过昼夜 提交于 2021-02-17 03:03:50
问题 I'm currently learning about trees using java and i have some errors going on here in the insertion of items in a binary tree I don't why it doesn't work this is the code: tree node: public class TNode { int data; TNode left; TNode right; public TNode(int data) { this.data = data; left = null; right = null; } } tree class: public class Tree { TNode root; public Tree(){ root = null; } public TNode insertNode(TNode item, int d) { if (item == null) { return new TNode(d); } if (d < item.data) {

LINQ contains one match from array of strings

北慕城南 提交于 2021-02-16 16:01:48
问题 Having trouble getting this to work: /// <summary> /// Retrieve search suggestions from previous searches /// </summary> public static string[] getSearchSuggestions(int SectionID, string Query) { string[] Suggestions; string[] Words = Query.Split(' '); using (MainContext db = new MainContext()) { Suggestions = (from c in db.tblSearches where c.SectionID == SectionID && Words.Any(w => c.Term.Contains(w)) select c.Term).ToArray(); } return Suggestions; } I get: System.NotSupportedException:

LINQ contains one match from array of strings

核能气质少年 提交于 2021-02-16 16:01:41
问题 Having trouble getting this to work: /// <summary> /// Retrieve search suggestions from previous searches /// </summary> public static string[] getSearchSuggestions(int SectionID, string Query) { string[] Suggestions; string[] Words = Query.Split(' '); using (MainContext db = new MainContext()) { Suggestions = (from c in db.tblSearches where c.SectionID == SectionID && Words.Any(w => c.Term.Contains(w)) select c.Term).ToArray(); } return Suggestions; } I get: System.NotSupportedException:

Find x-digit number in a text using Python

為{幸葍}努か 提交于 2021-02-16 09:22:13
问题 Is there a better (more efficient) way to find x-digit number (number consisted of x digits) in a text? My way: EDIT: for n in range(0,len(text)): if isinstance(text[n:n+x], (int)) and isinstance(text[n:n+x+1] is False: result = text[n:n+x] return result EDIT 2: for n in range(0,len(text)): try: int(text[n:n+x]) result = text[n:n+x] except: pass return result 回答1: import re string = "hello 123 world 5678 897 word" number_length = 3 pattern= r"\D(\d{%d})\D" % number_length # \D to avoid

Using Binary Search with Vectors.

﹥>﹥吖頭↗ 提交于 2021-02-16 08:55:32
问题 I'm trying to implement an algorithm that for each string in the first vector it does a binary search in the second vector and will output "YES:" if it finds a match or "No:" otherwise. Right now with my program my algo always outputs "NO:" and I can't find out what's going wrong. Any hints or tips would be appreciated. My Binary search: bool binary_search(const vector<string>& sorted_vec, string key) { size_t mid, left = 0 ; size_t right = sorted_vec.size(); // one position passed the right

Using Binary Search with Vectors.

不打扰是莪最后的温柔 提交于 2021-02-16 08:55:17
问题 I'm trying to implement an algorithm that for each string in the first vector it does a binary search in the second vector and will output "YES:" if it finds a match or "No:" otherwise. Right now with my program my algo always outputs "NO:" and I can't find out what's going wrong. Any hints or tips would be appreciated. My Binary search: bool binary_search(const vector<string>& sorted_vec, string key) { size_t mid, left = 0 ; size_t right = sorted_vec.size(); // one position passed the right

Count Total Amount Of Specific Word In a String JavaScript

谁说我不能喝 提交于 2021-02-15 07:43:42
问题 I want to find out how many time a specific words occur in a String JavaScript, or we can say the total amount of matched/match word with the complete sentence string in JavaScript. query = "fake"; var inputString = "fakefakefakegg fake 00f0 221 Hello wo fake misinfo fakeddfakefake , wo misinfo misinfo co wo fake , fake fake fake "; expected result = 13 (there is 13 fake in the above sentence) 回答1: Here are two methods to find the total number of occurrence match words in the string. The

Count Total Amount Of Specific Word In a String JavaScript

做~自己de王妃 提交于 2021-02-15 07:43:34
问题 I want to find out how many time a specific words occur in a String JavaScript, or we can say the total amount of matched/match word with the complete sentence string in JavaScript. query = "fake"; var inputString = "fakefakefakegg fake 00f0 221 Hello wo fake misinfo fakeddfakefake , wo misinfo misinfo co wo fake , fake fake fake "; expected result = 13 (there is 13 fake in the above sentence) 回答1: Here are two methods to find the total number of occurrence match words in the string. The

How to hightlight the typed text in searchview in android

坚强是说给别人听的谎言 提交于 2021-02-13 17:29:48
问题 Hi in the MainActivity I was Implemented a Different Fragments.Now toolbar contains a searchview functionality I was added in my Activity. Now I search for text all the fragement are also searching for same text.But I want to clear the text which one i typed for last fragement. MainActivity: toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); setSearchtollbar(); public void setSearchtollbar() { searchtollbar = (Toolbar) findViewById(R.id.searchtoolbar); if (searchtollbar !=

How to hightlight the typed text in searchview in android

烂漫一生 提交于 2021-02-13 17:28:06
问题 Hi in the MainActivity I was Implemented a Different Fragments.Now toolbar contains a searchview functionality I was added in my Activity. Now I search for text all the fragement are also searching for same text.But I want to clear the text which one i typed for last fragement. MainActivity: toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); setSearchtollbar(); public void setSearchtollbar() { searchtollbar = (Toolbar) findViewById(R.id.searchtoolbar); if (searchtollbar !=