Zulfi Khan
July 29th, 1999, 12:27 AM
Can somebody help me in understanding the addToList (class SimpleQueue) recursive method in the following code??
I particularly donot understand the "return N"
statement in that method.
In my view inth else part, it goes to the end of list & then the contructor of QNode is called which stores the data in the new element of queue. But what is the purpose of "return N"
statement?? How many times its being called??
Zulfi.
class QNode {
public String dataItem;
public QNode next;
public QNode(String entry){
dataItem = entry;
next = null;
}
}
class SimpleQueue {
QNode top;
public SimpleQueue() {
top = null;
}
public void addEntry(String entry) {
top = addToList(top, entry);
}
private QNode addToList
(QNode N, String entry){
if (N == null)
return new QNode(entry);
else {
N.next = addToList(N.next, entry);
return N;
}
}
}
I particularly donot understand the "return N"
statement in that method.
In my view inth else part, it goes to the end of list & then the contructor of QNode is called which stores the data in the new element of queue. But what is the purpose of "return N"
statement?? How many times its being called??
Zulfi.
class QNode {
public String dataItem;
public QNode next;
public QNode(String entry){
dataItem = entry;
next = null;
}
}
class SimpleQueue {
QNode top;
public SimpleQueue() {
top = null;
}
public void addEntry(String entry) {
top = addToList(top, entry);
}
private QNode addToList
(QNode N, String entry){
if (N == null)
return new QNode(entry);
else {
N.next = addToList(N.next, entry);
return N;
}
}
}