making letters out of a word [c#]

Started by
17 comments, last by rob64464 20 years, 1 month ago
What is the point of sorting? Just count the instances of each letter in WordMadeOutOfMainWord and make sure there are the same number in MainWord.
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
Advertisement
Hello,
How do I go to that function? contains(); does not work. How do I get to it then?
[EDIT; nevermind - foot->mouth]

what do you mean contains() doesn't work? does it not compile? does it crash? did you copy his code and compile it? show us how you used the function.

-me



[edited by - Palidine on March 24, 2004 3:59:16 PM]
How does it? I am trying to access the code from a picturebox click. But how do I goto that function? What code do you want? I don''t have any thats why I am asking you. The other algorithms do not work out and compare single characters.

Thanks,
Rob
quote:Original post by rob64464
Hello,
How do I go to that function? contains(); does not work. How do I get to it then?


here is where you said contains(); does not work. that implies you tried to use his function and it didn''t work. so how did you try and use his function?

um, basic stuff in case this is where you''re stumbling:

this is how you call one function from another
bool contains(string s1, string s2) {  char [] a1 = s1.ToCharArray();  char [] a2 = s2.ToCharArray();  Array.Sort(a1);  Array.Sort(a2);  s1 = new string(a1);  s2 = new string(a2);  while (s2 != "") {    int position = s1.IndexOf(s2[0]);    if (position == -1) return false;    s1 = s1.Remove(0, position + 1);    s2 = s2.Remove(0, 1);  }  return true;}int main(){    std::string one = "one";    std::string two = "two";    if (contains(one, two))        std::cout << "it''s in there\n";    else        std::cout << "it''s not in there\n";}


-me
quote:Original post by CodeMunkie
What is the point of sorting? Just count the instances of each letter in WordMadeOutOfMainWord and make sure there are the same number in MainWord.

The sorting allows for short-circuiting when searching for each individual letter in the second word. By always removing from the front part of each string, the intermediate values are easier to follow in a debugger. Also, the algorithm chosen was one that was expressible in a minimal number of control constructs. Basically, it''s code that tries to be easy to write correctly the first time and easy to debug if it does go wrong.
quote:Original post by rob64464
How does it? I am trying to access the code from a picturebox click. But how do I goto that function?

Didn''t we already talk about this in your "compare strings" thread? The easy way is to just define the function in the same scope with your on click handler.
quote:Original post by Palidine
this is how you call one function from another

// code snipped //


This is C# not C++.
quote:Original post by SiCrane
The sorting allows for short-circuiting when searching for each individual letter in the second word. By always removing from the front part of each string, the intermediate values are easier to follow in a debugger. Also, the algorithm chosen was one that was expressible in a minimal number of control constructs. Basically, it''s code that tries to be easy to write correctly the first time and easy to debug if it does go wrong.


Counting the number of occurrances of each letter has the same effect, yes? In which case, I gave a useful answer before the OP started claiming that people were misunderstanding him. Teh Grr.

This topic is closed to new replies.

Advertisement