1.单链表的基础结构节点`
private class Node{
Node next;
int x;
Node(int p) {
this.x= p;
}
public Node() {
}
}
2.建立单链表
public Node head = new Node();
public int size;
public void add(int t) {
//建立单链表
Node temp = head;
while (temp.next != null) {
temp = temp.next;
}
temp.next = new Node(t);
size++;
}
3.单链表的遍历
public void printData() {
//把第一个节点给临时节点temp,让temp遍历
Node temp = head;
while (temp != null) {
temp = temp.next;
System.out.print(temp.p.latitude+" ");
if(temp.next==null)//防止空指针
break;
}
System.out.println();
}
4.根据某个节点查询内容
public int get(int i) {
//查询链表的第i