我打算编写一个java程序来管理特定地点(姓名,地址,电话等)的人口数据,并且必须使用数据结构来实现。
所以我的问题是哪种数据结构对此最实用? (它还将添加,显示,删除,排序)。
我尝试使用链接列表,但我感觉不是正确的方法。感谢。
答案 0 :(得分:0)
这是一个非常模糊的外壳,就像你描述的那样。您似乎不喜欢LinkedLists,所以现在您可以使用二进制搜索树。在Wikipedia上查找二进制搜索树并实现所有空方法。
public class Population {
private String name;
private String address;
private String phoneNumber;
public Population(String name, String address, String phoneNumber) {
this.name = name;
this.address = address;
this.phoneNumber = phoneNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public int compareTo(Population o) {
return 0;
}
}
public class MyNode {
private Population data;
private MyNode left;
private MyNode right;
public MyNode(Population data, MyNode left, MyNode right) {
this.data = data;
this.left = left;
this.right = right;
}
public Population getData() {
return data;
}
public void setData(Population data) {
this.data = data;
}
public MyNode getLeft() {
return left;
}
public void setLeft(MyNode left) {
this.left = left;
}
public MyNode getRight() {
return right;
}
public void setRight(MyNode right) {
this.right = right;
}
}
public class MyTree {
private MyNode root;
public MyTree(MyNode root) {
this.root = root;
}
public MyTree() {
this.root = null;
}
public void insert(MyNode node) {
}
public void remove(MyNode node) {
}
public boolean isEmpty() {
return false;
}
public MyNode search(MyNode node) {
return null;
}
}