Initial Checkin
This commit is contained in:
57
LinkedList1.java
Normal file
57
LinkedList1.java
Normal file
@@ -0,0 +1,57 @@
|
||||
public class LinkedList1 {
|
||||
|
||||
public static void main(String []args) {
|
||||
|
||||
MyLinkedListElement le1 = new MyLinkedListElement();
|
||||
le1.setData("Data1");
|
||||
|
||||
MyLinkedListElement le2 = new MyLinkedListElement();
|
||||
le2.setData("Data2");
|
||||
le1.setNextElement(le2);
|
||||
|
||||
MyLinkedListElement le3 = new MyLinkedListElement();
|
||||
le3.setData("Data3");
|
||||
le2.setNextElement(le3);
|
||||
|
||||
MyLinkedListElement x = new MyLinkedListElement();
|
||||
x.setData("DataX");
|
||||
le1.setNextElement(x);
|
||||
x.setNextElement(le2);
|
||||
|
||||
eleTest(le1);
|
||||
}
|
||||
|
||||
public static void eleTest(MyLinkedListElement ele){
|
||||
while (ele != null){
|
||||
System.out.println(ele.getData());
|
||||
ele = ele.getNextElement();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MyLinkedListElement {
|
||||
private String data;
|
||||
private MyLinkedListElement nextElement;
|
||||
|
||||
public MyLinkedListElement getNextElement() {
|
||||
return nextElement;
|
||||
}
|
||||
|
||||
public void setNextElement(MyLinkedListElement nextElement) {
|
||||
this.nextElement = nextElement;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user