私は、ユーザが自分の値で挿入できるノードでいっぱいのダブルリンクリストを作成しなければならないプログラムを書いています。新しいノードをリストの異なる部分(正面、位置、尾)に挿入するメソッドがあります。各ノードには2つの情報、1つのStringと1つのINTがあります(どちらも新しいノードを作成した後にユーザーによって設定されます)。 ここで私の問題は、最初の情報をStringとして設定する方法ですボット要素INTが、最初の文字列でなければならず、私は助けを必要とする場合、これはある)TREE NODE <T>に2つの情報[STRING.INT]を設定するにはどうすればよいですか?
public void insertInFirstPosition(int information,int key) {
Node n = new Node(information,key, null, null);
if (head == null) {
n.setLinkNext(n);
n.setLinkPrev(n);
head = n;
tail = head;
} else {
n.setLinkPrev(tail);
tail.setLinkNext(n);
head.setLinkPrev(n);
n.setLinkNext(head);
head = n;
}
size++;
}
HEREノードクラスは ' パブリッククラスノード{
private int data;
private int informazione;
private Node next, prev;
/* Constructor */
public Node() {
next = null;
prev = null;
data = 0;
informazione = 0;
}
public Node(int i,int k, Node n, Node p) {
data = i;
informazione = k;
next = n;
prev = p;
}
/* Function to set link to next node */
public void setLinkNext (Node n) {
next = n;
}
/* Function to set link to previous node */
public void setLinkPrev(Node p) {
prev = p;
}
/* Funtion to get link to next node */
public Node getNext() {
return next;
}
/* Function to get link to previous node */
public Node getPrev() {
return prev;
}
/* Function to set information to node */
public void setInformazione(int i) {
informazione = i;
}
/* Function to get data from node */
public int getInformazione() {
return informazione;
}
/* Function to set data to node */
public void setData(int d) {
data = d;
}
/* Function to get data from node */
public int getData() {
return data;
}
} `
ISこのコードでは、両方のノードスロットのNT値、2番目のスロットは細かいですが、intでなければなりません。一方、最初のスロットは文字列でなければなりません。 ありがとうございました。
にパラメータタイプを変更します'文字列情報'? –
もしそうなら、2行目はすべてエラーとしてマークされます。それは私がそれを行う方法を理解できない理由です – Artyy
最初の引数だけが型を変更する可能性がありますか? 2番目の引数は常に 'int'ですか? –