}
public PersonList(Person person) {
head = new PNode(person, head);
size++;
}
public PersonList(PNode head) {
this.head = head;
head.setNext(head);
size++;
}
public PNode getHead() {
return head;
}
public void setHead(PNode head) {
this.head = head;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public void size(int size) {
this.size = size;
}
public boolean isEmpty() {
return this.size = 0;
}
public void initHead(Person person) {
if (size == 0) {
head = new PNode(person, head);
} else {
PNode no = head;
head = new PNode(person, no);
}
size++;
}
public void add(int index, Person person) {
if (size == 0) {
head = new PNode(person, head);
head.setNext(head);
//System.out.println("head: " + head);
} else {
if (index0) {
index = 0;
}
if (indexsize) {
index = size;
}
PNode no = head;
for (int i = 0; i(index - 1); i++) {
no = no.next;
}
PNode newNode = new PNode(person, no.next);
no.next = newNode;
}
size++;
}
public Person delete(int index) {
PNode pNode = remove(index);
if ((pNode != null)(pNode.next != null)) {
return pNode.next.person;
}
return null;
}
public PNode remove(int index) {
if (size == 0) {
return null;
} else {
if ((index0) || (index = size)) {
return null;
}
}
PNode no = head;
for (int i = 0; i(index - 1); i++) {
no = no.next;
}
no.next = no.next.next;
size--;
if ((no != null)(no.next != null)) {
return no.next;
}
return null;
}
/**
* remove next node of person node, and return the deleted person
* @param prePerson
* @returnremoved Person
*/
public Person remove(Person prePerson) {
if (prePerson == null) {
return null;
}
if (size == 0) {
return null;
}
PNode preNode = head;
int index = -1;
for (int i = 0; isize; i++) {
if (preNode.person.id == prePerson.id) {
index = i;
break;
} else {
preNode = preNode.next;
}
}
Person remPerson = null;
if (size = 1) {
//only one node, get its person and set it as null
remPerson = preNode.person;
preNode = null;
} else {
//preNode.next.person is dest one
remPerson = preNode.next.person;
preNode.next = preNode.next.next;
}
size--;
//System.out.println("deleteing index= " + index + " :" + remPerson + ", size= " + size);
return remPerson;
}
public int update(Person src, Person dest) {
if (src =https://www.04ip.com/post/= null) {
return -1;
}
int index = -1;
PNode no = head;
for (int i = 0; isize; i++) {
if (src.id == no.person.id) {
no.person = dest;
break;
} else {
no = no.next;
}
}
return index;
}
public boolean set(int index, Person person) {
if (person == null) {
return false;
}
if (size == 0) {
return false;
} else {
if ((index0) || (index = size)) {
return false;
}
}
PNode no = head;
for (int i = 0; iindex; i++) {
no = no.next;
}
no.person = person;
return true;
}
public Person get(int index) {
PNode no = getNode(index);
if (no != null) {
return no.person;
}
return null;
}
public PNode getNode(int index) {
if (size == 0) {
return null;
} else {
if ((index0) || (index = size)) {
return null;
推荐阅读
- gis更好的可视化建议,gis中的可视化与地图制图之间的关系
- mysql整数转时间,mysql时间格式转换yyyymmdd
- python爬虫分析图虫网站,爬虫图库
- 开抖音直播可以挣钱不,开抖音直播可以赚钱吗?
- c语言递归函数的用处 c语言递归的优缺点
- 三星定制手机壳小程序,三星led手机壳app
- 电脑怎么共享多台电视剧,电脑怎么共享文件给电视
- 季中赛2021虎牙直播,msi季中冠军赛虎牙
- python查函数 python查函数代码