[英]Recursive Logic for Linked List in Java
我試圖找到一種方法來編寫帶有遞歸邏輯的Java程序,以用於插入,搜索以及遍歷單鏈表。 但是,當頭節點為私有時,我不知道該怎么辦。 這是我編寫的代碼:
class Node {
int data;
Node next;
}
public class SingleList {
private Node head;
public SingleList() {
head = null;
}
void insert(Node temp, int num, int n) {
//Suggest some code here
}
boolean search(Node temp, int num) {
//Suggest some code here
}
void traverse(Node temp) {
//Suggest some code here
}
}
您可以從班級訪問主管。
此外, Node
類可能與SingleList
類以外的任何其他類都不相關,最好將其包含在SingleList
類中
public class SingleList {
private class Node {
int data;
Node next;
}
// Rest of your class code...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.