public class SingleLink {
private Node head;
private int size;
private class Node{
private Object data;
private Node next;
public Node(Object data) {
this.data = data;
}
}
public SingleLink() {
// TODO Auto-generated constructor stub
head = null;
size = 0;
}
public Object addHead(Object obj) {
Node node = new Node(obj);
if(size==0) {
head = node;
}else {
node.next=head;
head = node;
}
size++;
return obj;
}
public Object add(Object obj) {
Node node = new Node(obj);
if(size==0) {
head = node;
}else {
head.next = node;
}
size++;
return obj;
}
public Object removeHead() {
Object obj = head.data;
if(size==0) {
throw new IndexOutOfBoundsException();
}else if(size==1){
head = null;
}else {
head = head.next;
}
size--;
return obj;
}
public Node findData(Object obj) {
Node current = head;
for(int i=0;i<size;i++) {
if(current.data==obj) {
return current;
}else {
current = current.next;
}
}
return null;
}
public boolean removeData(Object obj) {
Node current = head;
Node previous = head;
if(size==0) {
return false;
}
while(current.data !=obj) {
if(current.next ==null) {
return false;
}else {
previous = current;
current = current.next;
}
}
if(current==head) {
head = current.next;
size--;
}else {
previous.next = current.next;
current.next = null;
size--;
}
return true;
}
public boolean isEmpty() {
return (size==0);
}
public void display() {
if(size>0) {
Node node = head;
int tempSize =size;
if(size==1) {
System.out.println("["+node.data+"]");
return;
}
while(tempSize>0) {
if(node==head) {
System.out.print("["+node.data+"->");
}else if(node.next ==null) {
System.out.print(node.data+"]");
}else {
System.out.print(node.data+"->");
}
node = node.next;
tempSize--;
}
System.out.println();
}else {
System.out.println("[]");
}
}
}
2.使用
public class SingleList {
public static void main(String[] args) {
SingleLink link = new SingleLink();
link.addHead("aaa");
link.display();
link.add("bbb");
link.display();
link.addHead("ccc");
link.display();
link.removeHead();
link.display();
}
}
问题:
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
解决参考ÿ…
IntelliJ IDEA 近期连续发布多个EAP版本,官方在对用户体验不断优化的同时,也新增了一些不错的功能,尤其是人工智能助手补充,AI Assistant,相信在后续IDEA使用中,会对开发者工作效率带来不错的提升。 以下是…