|
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.
|
|
|
|
|
can somebody provide me the source code for student information system......it would be of gr8 help to me...
|
|
|
|
|
There is a very good student information system: Google.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
i tried searching for it but couldnt find one it would be gr8 if u can post the link....
|
|
|
|
|
Student Information System
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
|
Very good observation, you catch on quick. Now if only we could link you <-> google....
|
|
|
|
|
The University of Utrecht offers one, I think.
Not sure where, exactly. You could try to contact them.
UU[^] (site in English, of course)
|
|
|
|
|
I'm feeling generous today so here you go...
public class Student
{
public Student(Information information)
{
Information = information;
}
public Information Information
{
get;
set;
}
}
public class Information
{
}
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)
|
|
|
|
|
Filofax.
Edit: It doesn't matter how many times you try to one-vote. I don't care. Just know that to do so without posting a comment is cowardly. If you think you have an opinion of my posts, then share it
|
|
|
|
|
I using access database for some application.
I update some values in the access - and i getting the information from the same table in same thread - and i see that the values are not right and not update correctly. How can i know if the data was update already ?
Is there some option to get some event when the table in the database done update ?
|
|
|
|
|
How to a Control to the NonClient area of Form in C#?
Fly Like An Eagle With MIGHTY POWER.
|
|
|
|
|
Define "control". What is it you want to do with the NC area??
|
|
|
|
|
Control means like Button,RadioButton ,CheckBox,Slider Control,Numeric updown and etc...
Fly Like An Eagle With MIGHTY POWER.
|
|
|
|
|
Your explanation doesn't clear things up. Are you saying that you want to put those controls in the TitleBar of a window??
|
|
|
|
|
How to develop chat application without server for LAN,
in articles I saw application only whith server-part and client-part
I want leart, how develop chat application (multiuser) whithot server
Thanks
upyachka watches you
|
|
|
|
|