|
yup its increaing exponentially. thats the code
private void button1_Click(object sender, EventArgs e)
{
listView1.Items.Clear();
lst.Clear();
str.Clear();
dummy = textBox1.Text.ToCharArray() ;
for (int i = 0; i < dummy.Length; i++)
str.Add(dummy[i]);
for (int i = 0; i < str.Count; i++)
{
root = new Node();
first(root);
recursive(root);
addlist(root, null);
char c = str[0];
str.RemoveAt(0);
str.Add(c);
}
lstview(); // adding lst to listview
}
private void addlist(Node current, Node parant)
{
if (current == null)
{
try
{
ch.RemoveAt(ch.Count - 1);
if (parant.NextCousion == null)
{
ch.RemoveAt(ch.Count - 1);
addlist(parant.parant.NextCousion, parant.parant.parant);
}
else
addlist(parant.NextCousion,parant.parant);
}
catch
{
return;
}
return;
}
ch.Add(current.data);
if(current.childerns.Count>0)
addlist(current.childerns[0],current);
if (current.childerns.Count == 0)
{
string s = "";
for (int i = 0; i < ch.Count; i++)
s += ch[i];
if(!lst.Contains(s))
lst.Add(s);
ch.RemoveAt(ch.Count - 1);
}
else
{
try
{
ch.RemoveAt(ch.Count - 1);
}
catch
{
return;
}
addlist(current.NextCousion,current.parant);
}
}
public void recursive(Node current)
{
for (int i = 0; i < str.Count- 1; i++)
layers(current.childerns[i]);
}
public void setingcousion(Node current)
{
int limit = current.childerns.Count;
for (int i = 0; i < limit; i++)
{
if (i == 0)
current.childerns[0].PreCousion = null;
else
{
current.childerns[i].PreCousion = current.childerns[i - 1];
current.childerns[i-1].NextCousion = current.childerns[i];
}
current.childerns[i].parant = current;
}
}
private void layers(Node current)
{
if (current == null)
return;
current.cousions = new List<Node>();
current.childerns = new List<Node>();
for (int i = 0; i < current.parant.childerns.Count ; i++)
{
if (current != current.parant.childerns[i])
{
current.cousions.Add(new Node(current.parant.childerns[i].data));
current.childerns.Add(new Node(current.parant.childerns[i].data));
}
}
for (int i = 0; i < current.childerns.Count; i++)
{
current.childerns[i].parant = current;
current.cousions[i].parant = current.parant;
}
setingcousion(current);
if (current.childerns.Count == 0)
{
layers(current.parant.NextCousion);
return;
}
for (int i = 0; i < current.childerns.Count; i++)
layers(current.childerns[i]);
}
|
|
|
|
|
public void first(Node current)
{
current.parant = null;
current.PreCousion = current.NextCousion = null;
current.childerns = new List<Node>();
current.data = str[0];
for (int i = 1; i < str.Count; i++)
{
if (i == 1)
{
current.childerns.Add(new Node(str[i]));
current.fisrtchild = current.childerns[0];
current.childerns[0].PreCousion = null;
}
else
{
current.childerns.Add(new Node(str[i]));
current.childerns[i - 1].PreCousion = current.childerns[i - 2];
current.childerns[i - 2].NextCousion = current.childerns[i - 1];
}
current.childerns[i - 1].parant = current;
}
}
i know my code is unreadable.
|
|
|
|
|
Hi,
there are 10! / 3! / 3! / 2! = 50400 unique permutations for "statistics".
my 30-line program finds them in 26 milliseconds with a simple recursion, basically without structs, arrays, lists.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
dear sir,
i have developed a software in c#, for reddit.com to automate processes. but i want to use proxy server to connect this site. i have to create one proxy server. but i dont know what is the actually use of proxy server and what is the need and how can i create one proxy server to connect this site.
do u have any idea. please share with me.
Thanks for any suggestion.
yogesh
|
|
|
|
|
yesb.Click += new System.EventHandler(this.Show());
nob.Click += new System.EventHandler(this.Close());
this is the error I keep getting:
An object reference is required for the nonstatic field, method, or property 'System.Windows.Forms.Control.Show()'
Same thing for this.Close() as well.
I have two buttons, one should reload the application, and the other closes it.
|
|
|
|
|
Interesting
Have you tried pressing TAB twice after writing the +=?
Putting the show/close in those methods may be more.. reliable (as in: no chance that it could go wrong)
|
|
|
|
|
No I haven't. I used this.Close() before and it worked fine.
|
|
|
|
|
Of course it does, but I don't think you're putting it in the right place. If you had pressed tab twice, you would get code like DaveyM69 shows you.
|
|
|
|
|
You can't call Show or Close this way unless you overload the methods i.e
yesb.Click += new EventHandler(Show);
void Show(object sender, EventArgs e)
{
Show();
} The normal way is to have a Click event handler and call Show from there - the same really - just a more logical name.
yesb.Click += new EventHandler(yesb_Click);
void yesb_Click(object sender, EventArgs e)
{
Show();
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Thank you! It worked
|
|
|
|
|
when i created a data source i get the following error:
An error occured while creating data source
Could not get type information for 'Example1.Example1.DataSet
It would be gr8fi anybody can help me with this to run the program successfully..
|
|
|
|
|
i m working with recursion and i have got an exception that says stack overflow
any solution?
|
|
|
|
|
It will be hard to identify the problem without code... code you post the code where this is happening?
|
|
|
|
|
hotthoughtguy wrote: any solution
Yes, dont exceed the stack size. Thats about as detailed answer as you can get based on the info provided.
|
|
|
|
|
Does this occur quickly or after a long run time? The former case of stack overflow often occurs due to infinite recursion.
It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains.
-- Pride and Prejudice and Zombies
|
|
|
|
|
You got this message because you didn't put anny kind of a bailout condition check into your method that's calling itself.
|
|
|
|
|
its not infinite recursion.its a program that gives you all possible combination of input string such as ABC.
so combination will be ABC ACB BAC BCA CAB CBA. i hv made a general tree n then traversing that tree through recursion. but it throws exception in words grater then length of 7. such as statistics.
|
|
|
|
|
The required recursion depth for words of length N is no more than N when done correctly.
There must be a logical error somewhere; check with a short word where some letters occur more than once
("aha").
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
public class Node
{
public List<Node> childerns;
public List<Node> cousions;
public Node parant;
public int IndexOfCousion;
public Node NextCousion;
public Node PreCousion;
public Node fisrtchild;
public Node()
{
}
public Node(char c)
{
data = c;
}
public char data;
}
private void layers(Node current)
{
if (current == null)
return;
current.cousions = new List<Node>();
current.childerns = new List<Node>();
for (int i = 0; i < current.parant.childerns.Count ; i++)
{
if (current != current.parant.childerns[i])
{
current.cousions.Add(new Node(current.parant.childerns[i].data));
current.childerns.Add(new Node(current.parant.childerns[i].data));
}
}
for (int i = 0; i < current.childerns.Count; i++)
{
current.childerns[i].parant = current;
current.cousions[i].parant = current.parant;
}
setingcousion(current);
if (current.childerns.Count == 0)
{
layers(current.parant.NextCousion);
return;
}
for (int i = 0; i < current.childerns.Count; i++)
layers(current.childerns[i]);
}
in input string statistics it throws exception stack overflow
|
|
|
|
|
Hi,
1.
thank you for the code. It is unreadable, lacking PRE tags which would have preserved formatting. Also the start is missing i.e. how is the string input in this?
2.
you did not react on my simple suggestion to try a short word with repeat characters ("aha").
3.
your Node is carrying too much data, most of which is redundant, and hence a small mistake somewhere will make nodes inconsistent, and the algorithm very hard to debug.
4.
NextCousion never gets initialized?
5.
layers(current.parant.NextCousion); is the biggest suspect. If I understand anything of your code, it seems to move sideways in the family tree, but downwards on the stack. That is a very bad idea, especially as I don't see a sideway limiting factor.
6.
there is just too much code for the simple job at hand. less code typically is easier to understand, and easier to debug (although it probably needs it less, since it typically also contains fewer bugs to start with).
7.
suggestion: throw it all out the window; rethink the matter and start afresh.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
its working with "NOON" , "TORONTO" . but when its "STATISTICS" it throws exp
|
|
|
|
|
hotthoughtguy wrote: its not infinite recursion
Then why are you exhausting the stack??
From what I could see in your code, not that it's very readable to start with, you're creating new child nodes, then INFINITELY, digging into those nodes and creating new ones.
Luc is right - scrap this and rethink what you're doing. You're going through a lot to do very little.
|
|
|
|
|
Hi everybody!
Hi have a problem when read dates from a strored procedure:
CREATE PROCEDURE
Articulos_GetByCodigo
(
@ParametroEntrada nvarchar(7)
)
AS
SET NOCOUNT ON
SELECT Gestion
FROM msTablaGestion
WHERE msTablaGestion.Codigo = @ParametroEntrada
SET QUOTED_IDENTIFIER OFF
GO
I call the method from a external method in the same class like this:
ExecuteStoreProcedure("Articulos_GetByCodigo", numeroPL);
articuloPermitido = reader.GetBoolean(0);
this is my method:
public void ExecuteStoreProcedure(string nombreProcedimiento,string parametro)
{
using (SqlConnection connection = new SqlConnection(cadenaConexion))
{
using (SqlCommand command = new SqlCommand(nombreProcedimiento,connection))
{
connection.Open();
//command.Connection = connection;
command.CommandType = System.Data.CommandType.StoredProcedure;
command.CommandText = nombreProcedimiento;
command.CommandTimeout = 10;
command.Parameters.AddWithValue("@parametroEntrada", parametro);
reader = command.ExecuteReader();
}
}
}
I receive in the call this : Metadata attempt invalid when the reader is closed
I think should be because i call the method and later the reader is closed, any have some sugestion.
P.D. I write the method outside because i want use this in another calls with another paremetres.
Thanks in advance
|
|
|
|
|
I believe the problem is that you are calling the reader outside of the scope of the readers command/connection objects. So inside of your method try this.
public void ExecuteStoreProcedure(string nombreProcedimiento,string parametro)
{
using (SqlConnection connection = new SqlConnection(cadenaConexion))
{
using (SqlCommand command = new SqlCommand(nombreProcedimiento,connection))
{
connection.Open();
command.CommandType = System.Data.CommandType.StoredProcedure;
command.CommandText = nombreProcedimiento;
command.CommandTimeout = 10;
command.Parameters.AddWithValue("@parametroEntrada", parametro);
reader = command.ExecuteReader();
while (reader.Read())
{
articuloPermitido = reader.GetBoolean(0);
}
}
}
}
Or you could have the method return the bool value from the reader.
|
|
|
|
|
Thanks Ian,
yes, i was thinking also this. My problem is that i wanted reuse the method for example for make another call like this
// This is the first one:
ExecuteStoreProcedure("Articulos_GetByCodigo", numeroPL);
articuloPermitido = Convert.ToBoolean(respuesta);
ExecuteStoreProcedure("Refrigerador_GetByIdTabla", numeroId);
if (IDTablaConservacion == 65)
articuloRefrigerador = true;
Where the sp Refrigerador_GetByIdTabla makes this query :
"Select IDTablaConservacion FROM Articulos where (IDTablaConservacion = '65' AND IDConservacion = '1') AND CodigoArticulo ='" + numeroId + "'";
Thanks and regards.
|
|
|
|