How to cut down the stack size?
hello,
public void ShortestPath(int i)
{
if(!(nod.contains(i)))
{
k=0;
nod.add(t, i);
}
while(k<node.elementAt(i).neighbours.size())
{
int a=node.elementAt(i).neighbours.elementAt(k);
if( a!=dest && !(nod.contains(a)))
{
// pos.add(t, k);
// t=t+1;
ShortestPath(a);
}
k++;
}
System.out.println("t=" + k);
}
In my program, System.out.println("t=" + k); is executing multiple times i.e the number of times the Shortestpath(i) is called. Here, how can i make the size of the stack to null. Can i?
thanks
Re: How to cut down the stack size?
Re: How to cut down the stack size?
Quote:
how can i make the size of the stack to null
What "stack" are you talking about?
Object reference variables can be assigned a null value, primitives can not.
Re: How to cut down the stack size?
Quote:
Originally Posted by
Norm
What "stack" are you talking about?
Object reference variables can be assigned a null value, primitives can not.
Thanks for your response.
I meant stack is called whenever the function calling to itself and the rest of the code following the function call is placed in the stack. here, in my problem the function is calling twice and so two times the following code is placed in stack. And so is the reason, 'System.out.print' is executing twice. I do not want that to happen and i.e., i should not be bothered about the stack.
hope you understand.
Thanks
Re: How to cut down the stack size?
The only time you should be bothered by the stack is when you use too much of it with a recursive method and it runs out of space.
If you don't like the way your code executes you should change it so it does what you want.
One way to skip out of the call stack could be to wrap the code in a try{} catch block and throw an exception when you want to pop up a bit. Never needed to do it, so am not sure if it would work.